@extends('layouts.app')
@section('content')
<div class="main-header">
    <div class="admin-header">
        <div class="uk-grid">
            <div class="uk-width-auto">
                <h1 class="uk-margin-small-top main-heading">{{$title}} ({{'#S'.$sellerRequest->id}})</h1>
            </div>
            <div class="uk-width-expand uk-text-right">
                <a class="uk-button uk-button-default" href="{{url('admin/seller-request/'.$sellerRequest->id)}}"> Back</a>
            </div>
        </div>
    </div>
</div>
<div class="uk-margin uk-width-1-1 uk-margin-auto uk-card uk-card-default uk-card-body small-padding">
    @include('partials.messages')
	{{ Form::open(array('route' => 'admin.seller-request.update', 'method' => 'POST', 'class' => 'uk-form-stacked','id' => 'edit_form')) }}
    @csrf
    {{ Form::hidden('seller_id', $sellerRequest->id) }}
    <div uk-grid>
    	<div class="uk-width-1-2@m">  
            <div class="uk-margin-small">
                <label for="province" class="uk-form-label">Province </label>
                <div class="uk-form-controls">
                    {{Form::select('province', $provinces, $sellerRequest->province,['class' => 'uk-select change-service-area','autocomplete' => 'off'])}}
                </div>    
            </div>
            <div class="uk-margin-small">
                <label for="region" class="uk-form-label">Region </label>
                <div class="uk-form-controls region-dropdown">
                    {{Form::select('region', $regions, $sellerRequest->region,['class' => 'uk-select change-region','autocomplete' => 'off'])}}    
                </div>
            </div> 
            <div class="uk-margin-small">
                <label for="city" class="uk-form-label">City </label>
                <div class="uk-form-controls city-dropdown">
                    {{Form::select('city', $cities, $sellerRequest->city,['class' => 'uk-select','autocomplete' => 'off'])}}    
                </div>
            </div>
            <div class="uk-grid-small" uk-grid>
                <div class="uk-width-expand@m">
                    <div class="uk-margin-small">
                        <label for="sell_price" class="uk-form-label">Sell Price </label>
                        <div class="uk-form-controls">
                            {{Form::text('sell_price', $sellerRequest->sell_price,['class' => 'uk-input','autocomplete' => 'off'])}}
                        </div>    
                    </div>
                </div>
                <div class="uk-width-1-6@m">
                    <div class="uk-margin-small">
                        <label for="sell_price_tag" class="uk-form-label">Sell Price Tag </label>
                        <div class="uk-form-controls">
                            {{Form::select('sell_price_tag', Config::get('enums.priceTag'), $sellerRequest->sell_price_tag,['class' => 'uk-select','autocomplete' => 'off'])}}
                        </div>    
                    </div>
                </div>
                <div class="uk-width-expand@m">
                    <div class="uk-margin-small">
                        <label for="bedroom" class="uk-form-label">Bedrooms </label>
                        <div class="uk-form-controls">
                            {{Form::select('bedroom', $bedrooms, $sellerRequest->bedrooms, ['class' => 'uk-select','autocomplete' => 'off'])}}
                        </div>    
                    </div>
                </div>
                <div class="uk-width-expand@m">
                    <div class="uk-margin-small">
                        <label for="bathroom" class="uk-form-label">Bathrooms </label>
                        <div class="uk-form-controls">
                            {{Form::select('bathroom', $bathrooms, $sellerRequest->bathrooms,['class' => 'uk-select','autocomplete' => 'off'])}}
                        </div>    
                    </div> 
                </div>
            </div>
            @php
                if($sellerRequest->parking){
                    $parkingData = json_decode($sellerRequest->parking, true);
                }else{
                    $parkingData = [];
                }
                
                if($sellerRequest->heating_fuel){
                    $heatingFuelData = json_decode($sellerRequest->heating_fuel, true);
                }else{
                    $heatingFuelData = [];
                }
                
                if($sellerRequest->amenities){
                    $amenitiesData = json_decode($sellerRequest->amenities, true);
                }else{
                    $amenitiesData = [];
                }
                
                if($sellerRequest->type_of_house){
                    $buildingData = json_decode($sellerRequest->type_of_house, true);
                }else{
                    $buildingData = [];
                }
            @endphp
            <div class="uk-margin-small">
                <div class="uk-grid-small" uk-grid>
                    <div class="uk-width-expand@m">
                        <div class="uk-margin-small">
                            <label for="sqft_property" class="uk-form-label">Building Area </label>
                            <div class="uk-form-controls">
                                {{Form::text('sqft_property', $sellerRequest->sqft_property,['class' => 'uk-input','autocomplete' => 'off'])}}
                            </div>    
                        </div>    
                    </div>
                    <div class="uk-width-1-4@m">
                        <div class="uk-margin-small">
                            <label for="building_area_tag" class="uk-form-label">Building Area Tag</label>
                            <div class="uk-form-controls">
                                {{Form::select('building_area_tag', Config::get('enums.buildingAreaTag'), $sellerRequest->building_area_tag,['class' => 'uk-select','autocomplete' => 'off'])}}
                            </div>    
                        </div>  
                    </div>
                </div>
            </div>
            <div class="uk-margin">
                <div class="uk-form-controls">
                    <label>{{Form::checkbox('senior_community', $sellerRequest->senior_community, $sellerRequest->senior_community == 1 ? true : false,['class' => 'uk-checkbox','autocomplete' => 'off'])}} Senior Community</label>
                </div>  
            </div>  
            <div uk-grid>
                <div class="uk-width-1-2@m">
                    <div class="uk-margin-small">
                        <label for="building_type" class="uk-form-label">Building Type </label>
                        @foreach($buildingTypes as $buildingType)
                        <div class="uk-form-controls">
                            <label>{{Form::checkbox('building_type[]', $buildingType->name, is_array($buildingData) && in_array($buildingType->name, @$buildingData),['class' => 'uk-checkbox','autocomplete' => 'off'])}} {{$buildingType->name}}</label>
                        </div>  
                        @endforeach
                    </div>
                </div>
                <div class="uk-width-1-2@m">
                    <div class="uk-margin-small">
                        <label for="parking" class="uk-form-label">Parking </label>
                        @foreach($parkings as $parking)
                        <div class="uk-form-controls">
                            <label>{{Form::checkbox('parking[]', $parking->name, is_array($parkingData) && in_array($parking->name, @$parkingData),['class' => 'uk-checkbox','autocomplete' => 'off'])}} {{$parking->name}}</label>
                        </div>  
                        @endforeach
                    </div>
                </div>
            </div>
            <div class="uk-margin-small">
                <label for="suite" class="uk-form-label">Is there a suite in your home? </label>
                <div class="uk-margin-small-top uk-grid-small uk-child-width-auto uk-grid">
                    <label>{{Form::radio('suite', 1, ($sellerRequest->suite == '1' ? true : ''), ['class' => 'uk-radio radio-check'])}} Yes</label>
                    <label>{{Form::radio('suite', 0, ($sellerRequest->suite == '0' ? true : ''), ['class' => 'uk-radio radio-check'])}} No</label>
                </div>
            </div> 
            <div class="suite-option-field {{$sellerRequest->suite == 1 ? '' : 'uk-hidden' }}">
                <div class="uk-margin-small uk-width-1-2@m">
                    <label for="suite_option" class="uk-form-label">Suite Option</label>
                    <div class="uk-form-controls">
                        {{Form::select('suite_option', Config::get('enums.suiteOption'), $sellerRequest->suite_option,['class' => 'uk-select','autocomplete' => 'off'])}}
                    </div>    
                </div>
            </div>
            <div class="uk-margin-small">
                <label for="buying_new_home" class="uk-form-label">Will you also be buying a new home? </label>
                <div class="uk-margin-small-top uk-grid-small uk-child-width-auto uk-grid">
                    <label>{{Form::radio('buying_new_home', 1, ($sellerRequest->buying_new_home == '1' ? true : ''), ['class' => 'uk-radio'])}} Yes</label>
                    <label>{{Form::radio('buying_new_home', 0, ($sellerRequest->buying_new_home == '0' ? true : ''), ['class' => 'uk-radio'])}} No</label>
                </div>
            </div>  
            <div class="uk-margin-small">
                <label for="already_buy_request" class="uk-form-label">Is your home currently listed for sale with another realtor? </label>
                <div class="uk-margin-small-top uk-grid-small uk-child-width-auto uk-grid">
                    <label>{{Form::radio('already_buy_request', 1, ($sellerRequest->already_buy_request == '1' ? true : ''), ['class' => 'uk-radio'])}} Yes</label>
                    <label>{{Form::radio('already_buy_request', 0, ($sellerRequest->already_buy_request == '0' ? true : ''), ['class' => 'uk-radio'])}} No</label>
                </div>
            </div> 
            <div class="uk-margin-small">
                <label for="currently_listed_realtor" class="uk-form-label">Have you added a buy request to Listing Llama already? </label>
                <div class="uk-margin-small-top uk-grid-small uk-child-width-auto uk-grid">
                    <label>{{Form::radio('currently_listed_realtor', 1, ($sellerRequest->currently_listed_realtor == '1' ? true : ''), ['class' => 'uk-radio'])}} Yes</label>
                    <label>{{Form::radio('currently_listed_realtor', 0, ($sellerRequest->currently_listed_realtor == '0' ? true : ''), ['class' => 'uk-radio'])}} No</label>
                </div>
            </div>  
        </div>
        <div class="uk-width-1-2@m">
            <div class="uk-margin-small">
                <label for="age_property" class="uk-form-label">Age Property </label>
                <div class="uk-form-controls">
                    {{Form::select('age_property', $ageProperties, $sellerRequest->age_property,['class' => 'uk-select','autocomplete' => 'off'])}}
                </div>    
            </div>
            <div class="uk-margin-small">
                <label for="preferred_neighbourhoods" class="uk-form-label">Preferred Neighbourhoods </label>
                <div class="uk-form-controls">
                    {{Form::textarea('preferred_neighbourhoods', $sellerRequest->preferred_neighbourhoods,['class' => 'uk-textarea','autocomplete' => 'off', 'rows' => '4'])}}
                </div>    
            </div>
            <div class="uk-margin-small">
                <label for="other_request" class="uk-form-label">Other Information / Feauters </label>
                <div class="uk-form-controls">
                    {{Form::textarea('other_request', $sellerRequest->other_request,['class' => 'uk-textarea','autocomplete' => 'off', 'rows' => '4'])}}
                </div>    
            </div>
            <div uk-grid>
                <div class="uk-width-1-2@m">
                    <div class="uk-margin-small">
                        <label for="amenities" class="uk-form-label">Other Feauters </label>
                        @foreach($amenities as $amenity)
                        <div class="uk-form-controls">
                            <label>{{Form::checkbox('amenities[]', $amenity->name, is_array($amenitiesData) && in_array($amenity->name, @$amenitiesData),['class' => 'uk-checkbox','autocomplete' => 'off'])}} {{$amenity->name}}</label>
                        </div>    
                        @endforeach
                    </div>
                </div>
                <div class="uk-width-1-2@m">
                    <div class="uk-margin-small">
                        <label for="heating_fuel" class="uk-form-label">Heating and Cooling </label>
                        @foreach($heatingFuels as $heatingFuel)
                        <div class="uk-form-controls">
                            <label>{{Form::checkbox('heating_fuel[]', $heatingFuel->name, is_array($heatingFuelData) && in_array($heatingFuel->name, @$heatingFuelData),['class' => 'uk-checkbox','autocomplete' => 'off'])}} {{$heatingFuel->name}}</label>
                        </div>    
                        @endforeach
                    </div>
                </div>
            </div>
        </div>
    </div>    
    <div class="uk-margin">
        <div class="uk-text-center">
            {{ Form::submit('Update', array('class' => 'uk-button uk-button-primary','name' => 'save', 'id' => 'edit_submit')) }}
            <a class="uk-button uk-button-default" href="{{url('admin/seller-request/'.$sellerRequest->id)}}"> Cancel</a>
        </div>
    </div>
    {{ Form::close() }}
</div>    
@endsection
@section('footer-script')
 <script>
 
    $(document).on('click','.radio-check',function(){
        if($(this).is(':checked')){
            if($(this).val() == 1){
                $('.suite-option-field').removeClass('uk-hidden');
            }else{
                $('.suite-option-field').addClass('uk-hidden');
            }
        }
    
    });
    
    $("#edit_form").validate({
        submitHandler: function(form) {
            $('#edit_submit').attr('disabled',true);
            form.submit();
        }
    });
    
    $(document).on('change','.change-service-area',function(){
        var province = $(this).val();

        $.ajax(
        {
            url: url + "/admin/select-region",
            type: 'POST',
            dataType: "JSON",
            data: {
                'province': province,
            },
            success: function (res)
            {
                if(res.success == 1){
                    $('.region-dropdown').html(res.html);
                }
            },
            error: function () {
                UIkit.modal.alert('Oops there was an error! Please try again.');
            }
        });
    });
    
    $(document).on('change','.change-region',function(){
        var region = $(this).val();

        $.ajax(
        {
            url: url + "/admin/seller-change-city",
            type: 'POST',
            dataType: "JSON",
            data: {
                'region': region,
            },
            success: function (res)
            {
                if(res.success == 1){
                    $('.city-dropdown').html(res.html);
                }
            },
            error: function () {
                UIkit.modal.alert('Oops there was an error! Please try again.');
            }
        });
    });
</script>
@endsection