<?php $__env->startSection('title'); ?>
    <?php echo e(__('Add Project')); ?>

<?php $__env->stopSection(); ?>
<!-- add before </body> -->


<?php $__env->startSection('page-title'); ?>
    <div class="page-title">
        <div class="row">
            <div class="col-12 col-md-6 order-md-1 order-last">
                <h4><?php echo $__env->yieldContent('title'); ?></h4>

            </div>
            <div class="col-12 col-md-6 order-md-2 order-first">
                <nav aria-label="breadcrumb" class="breadcrumb-header float-start float-lg-end">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item">
                            <a href="<?php echo e(route('project.index')); ?>" id="subURL"><?php echo e(__('View Project')); ?></a>
                        </li>
                        <li class="breadcrumb-item active" aria-current="page">
                            <?php echo e(__('Add')); ?>

                        </li>
                    </ol>
                </nav>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>
    <?php echo Form::open(['route' => 'project.store', 'data-parsley-validate', 'id' => 'create-form', 'files' => true,'data-success-function'=> "formSuccessFunction"]); ?>

    <div class='row'>
        <div class='col-md-6'>
            <div class="card">
                <h3 class="card-header"> <?php echo e(__('Details')); ?></h3>
                <hr>
                <input type="hidden" id="default-latitude" value="<?php echo e(system_setting('latitude')); ?>">
                <input type="hidden" id="default-longitude" value="<?php echo e(system_setting('longitude')); ?>">

                
                <div class="card-body">
                    <div class="col-md-12 col-12 form-group mandatory">
                        <?php echo e(Form::label('category', __('Category'), ['class' => 'form-label col-12 '])); ?>

                        <select name="category_id" class="form-select form-control-sm" data-parsley-minSelect='1' id="project-category" required>
                            <option value="" selected><?php echo e(__('Choose Category')); ?></option>
                            <?php $__currentLoopData = $category; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($row->id); ?>" data-parametertypes='<?php echo e($row->parameter_types); ?>'>
                                    <?php echo e($row->category); ?>

                                </option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>

                    
                    <div class="col-md-12 col-12 form-group mandatory">
                        <?php echo e(Form::label('title', __('Title'), ['class' => 'form-label col-12 '])); ?>

                        <?php echo e(Form::text('title', '', [ 'class' => 'form-control ', 'placeholder' =>  __('Title'), 'required' => 'true', 'id' => 'title', ])); ?>

                    </div>

                    
                    <div class="col-md-12 col-12 form-group">
                        <?php echo e(Form::label('slug', __('Slug'), ['class' => 'form-label col-12 '])); ?>

                        <?php echo e(Form::text('slug', '', [ 'class' => 'form-control ', 'placeholder' =>  __('Slug'), 'id' => 'slug', ])); ?>

                        <small class="text-danger text-sm"><?php echo e(__("Only Small English Characters, Numbers And Hypens Allowed")); ?></small>
                    </div>

                    
                    <div class="col-md-12 col-12 form-group mandatory">
                        <?php echo e(Form::label('description', __('Description'), ['class' => 'form-label col-12 '])); ?>

                        <?php echo e(Form::textarea('description', '', [ 'class' => 'form-control mb-3', 'rows' => '5', 'id' => '', 'required' => 'true', 'placeholder' => __('Description') ])); ?>

                    </div>

                    
                    <div class="col-md-12 col-12  form-group  mandatory">
                        <div class="row">
                            <?php echo e(Form::label('', __('Project Type'), ['class' => 'form-label col-12 '])); ?>


                            
                            <div class="col-md-6">
                                <?php echo e(Form::radio('project_type', 'upcoming', null, [ 'class' => 'form-check-input', 'id' => 'upcoming', 'required' => true, 'checked' => true ])); ?>

                                <?php echo e(Form::label('project_type', __('Upcoming'), ['class' => 'form-check-label','for' => 'upcoming'])); ?>

                            </div>

                            
                            <div class="col-md-6">
                                <?php echo e(Form::radio('project_type', 'under_construction', null, [ 'class' => 'form-check-input', 'id' => 'under_construction', 'required' => true, ])); ?>

                                <?php echo e(Form::label('project_type', __('Under Construction'), ['class' => 'form-check-label','for' => 'under_construction'])); ?>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class='col-md-6'>
            <div class="card">
                <h3 class="card-header"><?php echo e(__('SEO Details')); ?></h3>
                <hr>
                <div class="row card-body">

                    
                    <div class="col-md-6 col-sm-12 form-group">
                        <?php echo e(Form::label('title', __('Title'), ['class' => 'form-label text-center'])); ?>

                        <textarea id="meta_title" name="meta_title" class="form-control" oninput="getWordCount('meta_title','meta_title_count','12.9px arial')" rows="2" style="height: 75px" placeholder="<?php echo e(__('Title')); ?>"></textarea>
                        <br>
                        <h6 id="meta_title_count">0</h6>
                    </div>

                    
                    <div class="col-md-6 col-sm-12 form-group card">
                        <?php echo e(Form::label('meta_image', __('Image'), ['class' => 'form-label'])); ?>

                        <input type="file" name="meta_image" id="meta_image" class="filepond from-control" placeholder="<?php echo e(__('Image')); ?>">
                        <div class="img_error"></div>
                    </div>

                    
                    <div class="col-md-12 col-sm-12 form-group">
                        <?php echo e(Form::label('description', __('Description'), ['class' => 'form-label text-center'])); ?>

                        <textarea id="meta_description" name="meta_description" class="form-control" oninput="getWordCount('meta_description','meta_description_count','12.9px arial')" rows="3" placeholder="<?php echo e(__('Description')); ?>"></textarea>
                        <br>
                        <h6 id="meta_description_count">0</h6>
                    </div>

                    
                    <div class="col-md-12 col-sm-12 form-group">
                        <?php echo e(Form::label('keywords', __('Keywords'), ['class' => 'form-label'])); ?>

                        <textarea name="keywords" id="" class="form-control" rows="3" placeholder="<?php echo e(__('Keywords')); ?>"></textarea>
                        (add comma separated keywords)
                    </div>

                </div>
            </div>
        </div>

        
        <div class='col-md-12'>
            <div class="card">
                <h3 class="card-header"><?php echo e(__('Location')); ?></h3>
                <hr>
                <div class="card-body">

                    <div class="row">
                        <div class='col-md-6'>
                            <div class="card col-md-12" id="map" style="height: 90%">
                                <!-- Google map -->
                            </div>
                        </div>
                        <div class='col-md-6'>
                            <div class="row">
                                <div class="col-md-12 col-12 form-group mandatory">
                                    <?php echo e(Form::label('city', __('City'), ['class' => 'form-label col-12 '])); ?>

                                    <?php echo Form::hidden('city', '', ['class' => 'form-control ', 'id' => 'city']); ?>

                                    <input id="searchInput" class="controls form-control" type="text" placeholder="<?php echo e(__('City')); ?>" required>
                                    
                                </div>
                                <div class="col-md-6 form-group mandatory">
                                    <?php echo e(Form::label('country', __('Country'), ['class' => 'form-label col-12 '])); ?>

                                    <?php echo e(Form::text('country', '', ['class' => 'form-control ', 'placeholder' => 'Country', 'id' => 'country', 'required' => true])); ?>

                                </div>
                                <div class="col-md-6 form-group mandatory">
                                    <?php echo e(Form::label('state', __('State'), ['class' => 'form-label col-12 '])); ?>

                                    <?php echo e(Form::text('state', '', ['class' => 'form-control ', 'placeholder' => 'State', 'id' => 'state', 'required' => true])); ?>

                                </div>
                                <div class="col-md-6 form-group mandatory">
                                    <?php echo e(Form::label('latitude', __('Latitude'), ['class' => 'form-label col-12 '])); ?>

                                    <?php echo Form::text('latitude', '', ['class' => 'form-control', 'id' => 'latitude', 'step' => 'any', 'readonly' => true, 'required' => true, 'placeholder' => trans('Latitude')]); ?>

                                </div>
                                <div class="col-md-6 form-group mandatory">
                                    <?php echo e(Form::label('longitude', __('Longitude'), ['class' => 'form-label col-12 '])); ?>

                                    <?php echo Form::text('longitude', '', ['class' => 'form-control', 'id' => 'longitude', 'step' => 'any', 'readonly' => true, 'required' => true, 'placeholder' => trans('Longitude')]); ?>

                                </div>
                                <div class="col-md-12 col-12 form-group mandatory">
                                    <?php echo e(Form::label('address', __('Address'), ['class' => 'form-label col-12 '])); ?>

                                    <?php echo e(Form::textarea('address', '', [
                                        'class' => 'form-control ',
                                        'placeholder' => 'Address',
                                        'rows' => '4',
                                        'id' => 'address',
                                        'autocomplete' => 'off',
                                        'required' => 'true',
                                    ])); ?>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        
        <div class="col-md-12">
            <div class="card">
                <h3 class="card-header"><?php echo e(__('Floor Plans')); ?></h3>
                <hr>
                <div class="card-body projects-floor-plans">
                    
                    <div class="mt-4" data-repeater-list="floor_data">
                        <div class="row floor-section" data-repeater-item>
                            
                            <div class="form-group col-md-5">
                                <label class="form-label"><?php echo e(__('Floor')); ?> - <span class="floor-number">1</span> <span class="text-danger">*</span></label>
                                <input type="text" name="title" placeholder="<?php echo e(__('Enter Floor Title')); ?>" class="form-control" required>
                            </div>

                            
                            <div class="form-group col-md-6">
                                <?php echo e(Form::label('floor-image', __('Floor Image'), ['class' => 'form-label'])); ?>

                                <input type="file" class="form-control" name="floor_image" accept="image/jpg,image/png,image/jpeg" required>
                            </div>
                            <div class="form-group col-md-1 pl-0 mt-4">
                                <button data-repeater-delete type="button" class="btn btn-icon btn-danger remove-default-floor" title="<?php echo e(__('Remove Floor')); ?>">
                                    <i class="fa fa-times"></i>
                                </button>
                            </div>
                        </div>
                    </div>
                    
                    <div class="col-md-5 pl-0 mb-4">
                        <button type="button" class="btn btn-success add-new-floor" data-repeater-create title="<?php echo e(__('Add New Floor')); ?>">
                            <span><i class="fa fa-plus"></i> <?php echo e(__('Add New Floor')); ?></span>
                        </button>
                    </div>
                </div>
            </div>
        </div>


        
        <div class="col-md-12">
            <div class="card">
                <h3 class="card-header"><?php echo e(__('Images, Videos and Documents')); ?></h3>
                <hr>
                <div class="card-body">
                    <div class="row">
                        
                        <div class="col-sm-12 col-md-6 col-lg-4 col-xl-3  form-group mandatory">
                            <?php echo e(Form::label('title-image', __('Title Image'), ['class' => 'form-label'])); ?>

                            <input type="file" class="filepond" id="title-image" name="image" accept="image/jpg,image/png,image/jpeg" required>
                        </div>

                        
                        <div class="col-sm-12 col-md-6 col-lg-4 col-xl-3">
                            <?php echo e(Form::label('gallary-images', __('Gallery Images'), ['class' => 'form-label'])); ?>

                            <input type="file" class="filepond" id="gallary-images" name="gallery_images[]" multiple accept="image/jpg,image/png,image/jpeg">
                        </div>

                        
                        <div class="col-sm-12 col-md-6 col-lg-4 col-xl-3">
                            <?php echo e(Form::label('documents', __('Documents'), ['class' => 'form-label '])); ?>

                            <input type="file" class="filepond" id="documents" name="documents[]" multiple accept="application/pdf,application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document">
                        </div>

                        
                        <div class="col-md-3">
                            <?php echo e(Form::label('video_link', __('Video Link'), ['class' => 'form-label'])); ?>

                            <?php echo e(Form::text('video_link', isset($list->video_link) ? $list->video_link : '', [ 'class' => 'form-control ', 'placeholder' => 'Video Link', 'id' => 'address', 'autocomplete' => 'off', ])); ?>

                        </div>
                    </div>
                </div>
            </div>
        </div>

        
        <div class='col-md-12 d-flex justify-content-end mb-3'>
            <input type="submit" class="btn btn-primary" value="<?php echo e(__('Save')); ?>"> &nbsp;&nbsp;
            <button class="btn btn-secondary" type="button" onclick="myForm.reset();"><?php echo e(__('Reset')); ?></button>
        </div>
    </div>

    <?php echo Form::close(); ?>

<?php $__env->stopSection(); ?>
<?php $__env->startSection('script'); ?>
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?libraries=places&key=<?php echo e(env('PLACE_API_KEY')); ?>&callback=initMap" async defer></script>
    <script type="text/javascript">
        jQuery(document).ready(function() {
            initMap();
            $('#map').append('<iframe src="https://maps.google.com/maps?q=' + 20.593684 + ',' + 78.96288 + '&hl=en&amp;z=18&amp;output=embed" height="375px" width="800px"></iframe>');
        });

        $(document).ready(function() {
            getWordCount("meta_title", "meta_title_count", "19.9px arial");
            getWordCount("meta_description", "meta_description_count", "12.9px arial");
        });

        function initMap() {
            let defaultLatitude = parseInt($("#default-latitude").val() ?? -33.8688);
            let defaultLongitude = parseInt($("#default-longitude").val() ?? 151.2195);

            var map = new google.maps.Map(document.getElementById('map'), {
                center: {
                    lat: defaultLatitude,
                    lng: defaultLongitude
                },
                zoom: 8
            });
            var input = document.getElementById('searchInput');

            var autocomplete = new google.maps.places.Autocomplete(input);
            autocomplete.bindTo('bounds', map);

            var infowindow = new google.maps.InfoWindow();
            var marker = new google.maps.Marker({
                draggable: true,

                position: {
                    lat: defaultLatitude,
                    lng: defaultLongitude
                },
                map: map,
                anchorPoint: new google.maps.Point(0, -29)
            });
            google.maps.event.addListener(marker, 'dragend', function(event) {
                var geocoder = new google.maps.Geocoder();
                geocoder.geocode({
                    'latLng': event.latLng
                }, function(results, status) {
                    if (status == google.maps.GeocoderStatus.OK) {
                        if (results[0]) {
                            var address_components = results[0].address_components;
                            var city, state, country, full_address;

                            for (var i = 0; i < address_components.length; i++) {
                                var types = address_components[i].types;
                                if (types.indexOf('locality') != -1) {
                                    city = address_components[i].long_name;
                                } else if (types.indexOf('administrative_area_level_1') != -1) {
                                    state = address_components[i].long_name;
                                } else if (types.indexOf('country') != -1) {
                                    country = address_components[i].long_name;
                                }
                            }

                            full_address = results[0].formatted_address;

                            // Do something with the city, state, country, and full address
                            $('#searchInput').val(city);
                            $('#city').val(city);
                            $('#country').val(country);
                            $('#state').val(state);
                            $('#address').val(full_address);
                            $('#latitude').val(event.latLng.lat());
                            $('#longitude').val(event.latLng.lng());

                        } else {
                            console.log('No results found');
                        }
                    } else {
                        console.log('Geocoder failed due to: ' + status);
                    }
                });
            });
            autocomplete.addListener('place_changed', function() {
                infowindow.close();
                marker.setVisible(false);
                var place = autocomplete.getPlace();
                if (!place.geometry) {
                    window.alert("Autocomplete's returned place contains no geometry");
                    return;
                }
                if (place.geometry.viewport) {
                    map.fitBounds(place.geometry.viewport);
                } else {
                    map.setCenter(place.geometry.location);
                    map.setZoom(17);
                }
                marker.setIcon(({
                    url: place.icon,
                    size: new google.maps.Size(71, 71),
                    origin: new google.maps.Point(0, 0),
                    anchor: new google.maps.Point(17, 34),
                    scaledSize: new google.maps.Size(35, 35)
                }));
                marker.setPosition(place.geometry.location);
                marker.setVisible(true);

                var address = '';
                if (place.address_components) {
                    address = [
                        (place.address_components[0] && place.address_components[0].short_name || ''),
                        (place.address_components[1] && place.address_components[1].short_name || ''),
                        (place.address_components[2] && place.address_components[2].short_name || '')
                    ].join(' ');
                }

                infowindow.setContent('<div><strong>' + place.name + '</strong><br>' + address);
                infowindow.open(map, marker);

                // Location details
                for (var i = 0; i < place.address_components.length; i++) {

                    if (place.address_components[i].types[0] == 'locality') {
                        $('#city').val(place.address_components[i].long_name);


                    }
                    if (place.address_components[i].types[0] == 'country') {
                        $('#country').val(place.address_components[i].long_name);


                    }
                    if (place.address_components[i].types[0] == 'administrative_area_level_1') {
                        $('#state').val(place.address_components[i].long_name);


                    }
                }

                var latitude = place.geometry.location.lat();
                var longitude = place.geometry.location.lng();
                $('#address').val(place.formatted_address);


                $('#latitude').val(place.geometry.location.lat());
                $('#longitude').val(place.geometry.location.lng());

            });
        }
        jQuery(document).ready(function() {
            initMap();
            $('#map').append('<iframe src="https://maps.google.com/maps?q=' + 20.593684 + ',' + 78.96288 + '&hl=en&amp;z=18&amp;output=embed" height="375px" width="800px"></iframe>');
            $('.select2').prepend('<option value="" selected></option>');

        });
        $(document).ready(function() {
            FilePond.registerPlugin(FilePondPluginImagePreview, FilePondPluginFileValidateSize,FilePondPluginFileValidateType);
        });

        $("#title").on('keyup',function(e){
            let title = $(this).val();
            let slugElement = $("#slug");
            if(title){
                $.ajax({
                    type: 'POST',
                    url: "<?php echo e(route('project.generate-slug')); ?>",
                    data: {
                        '_token': $('meta[name="csrf-token"]').attr('content'),
                        title: title
                    },
                    beforeSend: function() {
                        slugElement.attr('readonly', true).val('Please wait....')
                    },
                    success: function(response) {
                        if(!response.error){
                            if(response.data){
                                slugElement.removeAttr('readonly').val(response.data);
                            }else{
                                slugElement.removeAttr('readonly').val("")
                            }
                        }
                    }
                });
            }else{
                slugElement.removeAttr('readonly', true).val("")
            }
        });

        function formSuccessFunction(response) {
            if(!response.error){
                setTimeout(() => {
                    window.location.reload();
                }, 500);
            }
        }
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.main', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/wrteam-shakir/ebroker/resources/views/project/create.blade.php ENDPATH**/ ?>