@extends('layouts.app')

@section('content')
    <h3 class="page-title">@lang('quickadmin.marker.title')</h3>
    
    {!! Form::model($marker, ['method' => 'PUT', 'route' => ['admin.markers.update', $marker->id]]) !!}

    <div class="panel panel-default">
        <div class="panel-heading">
            @lang('quickadmin.qa_edit')
        </div>

        <div class="panel-body">
            <div class="row">
                <div class="col-xs-12 form-group">
                    {!! Form::label('infrastructure_type_id', trans('quickadmin.marker.fields.infrastructure-type').'', ['class' => 'control-label']) !!}
                    {!! Form::select('infrastructure_type_id', $infrastructure_types, old('infrastructure_type_id'), ['class' => 'form-control select2']) !!}
                    <p class="help-block"></p>
                    @if($errors->has('infrastructure_type_id'))
                        <p class="help-block">
                            {{ $errors->first('infrastructure_type_id') }}
                        </p>
                    @endif
                </div>
            </div>

            <div class="row">
                <div class="col-xs-12 form-group">
                    {!! Form::label('residential_complex', trans('quickadmin.marker.fields.rc-name').'', ['class' => 'control-label']) !!}
                    <button type="button" class="btn btn-primary btn-xs" id="selectbtn-residential_complex">
                        {{ trans('quickadmin.qa_select_all') }}
                    </button>
                    <button type="button" class="btn btn-primary btn-xs" id="deselectbtn-residential_complex">
                        {{ trans('quickadmin.qa_deselect_all') }}
                    </button>
                    {!! Form::select('residential_complex[]', $residential_complexes, old('residential_complex') ? old('residential_complex') : $marker->residential_complexes->pluck('id')->toArray(), ['class' => 'form-control select2', 'multiple' => 'multiple', 'id' => 'selectall-residential_complex' ]) !!}
                    <p class="help-block"></p>
                    @if($errors->has('residential_complex'))
                        <p class="help-block">
                            {{ $errors->first('residential_complex') }}
                        </p>
                    @endif
                </div>
            </div>

            {{--<div class="row">--}}
                {{--<div class="col-xs-6 form-group">--}}
                    {{--{!! Form::label('latitude', trans('quickadmin.marker.fields.latitude').'*', ['class' => 'control-label']) !!}--}}
                    {{--{!! Form::text('latitude', old('latitude'), ['class' => 'form-control', 'placeholder' => '', ]) !!}--}}
                    {{--<p class="help-block"></p>--}}
                    {{--@if($errors->has('latitude'))--}}
                        {{--<p class="help-block">--}}
                            {{--{{ $errors->first('latitude') }}--}}
                        {{--</p>--}}
                    {{--@endif--}}
                {{--</div>--}}
                {{--<div class="col-xs-6 form-group">--}}
                    {{--{!! Form::label('longitude', trans('quickadmin.marker.fields.longitude').'*', ['class' => 'control-label']) !!}--}}
                    {{--{!! Form::text('longitude', old('longitude'), ['class' => 'form-control', 'placeholder' => '', ]) !!}--}}
                    {{--<p class="help-block"></p>--}}
                    {{--@if($errors->has('longitude'))--}}
                        {{--<p class="help-block">--}}
                            {{--{{ $errors->first('longitude') }}--}}
                        {{--</p>--}}
                    {{--@endif--}}
                {{--</div>--}}
            {{--</div>--}}
            <div>
                {!! Form::hidden('street_name', old('street_name'), ['class' => 'form-control', 'placeholder' => '', ]) !!}
            </div>
            {{--<div class="row">--}}
                {{--<div class="col-xs-12 form-group">--}}
                    {{--{!! Form::label('street_name', trans('quickadmin.marker.fields.street-name').'', ['class' => 'control-label']) !!}--}}
                    {{--{!! Form::text('street_name', old('street_name'), ['class' => 'form-control', 'placeholder' => '', ]) !!}--}}
                    {{--<p class="help-block"></p>--}}
                    {{--@if($errors->has('street_name'))--}}
                        {{--<p class="help-block">--}}
                            {{--{{ $errors->first('street_name') }}--}}
                        {{--</p>--}}
                    {{--@endif--}}
                {{--</div>--}}
            {{--</div>--}}
            <div class="row">
                <div class="col-xs-12 form-group">
                    {!! Form::label('address_address', trans('quickadmin.marker.fields.address').'*', ['class' => 'control-label']) !!}
                    {!! Form::text('address_address', old('address_address'), ['class' => 'form-control map-input', 'id' => 'address-input', ]) !!}
                    {!! Form::hidden('address_latitude', $marker->address_latitude , ['id' => 'address-latitude']) !!}
                    {!! Form::hidden('address_longitude', $marker->address_longitude , ['id' => 'address-longitude']) !!}
                    <p class="help-block"></p>
                    @if($errors->has('address_address'))
                        <p class="help-block">
                            {{ $errors->first('address_address') }}
                        </p>
                    @endif
                </div>
            </div>
            
            <div id="address-map-container" style="width:100%;height:200px; ">
                <div style="width: 100%; height: 100%" id="address-map"></div>
            </div>
            @if(!env('GOOGLE_MAPS_API_KEY'))
                <b>'GOOGLE_MAPS_API_KEY' is not set in the .env</b>
            @endif
        </div>
    </div>

    {!! Form::submit(trans('quickadmin.qa_update'), ['class' => 'btn btn-danger']) !!}
    {!! Form::close() !!}
@stop

@section('javascript')
    @parent
    <script src="{{ asset('adminlte/js/mapInput.js') }}"></script>
    <script src="https://maps.googleapis.com/maps/api/js?key={{ env('GOOGLE_MAPS_API_KEY') }}&libraries=places&callback=initialize"
            async defer></script>


    <script>
        $("#selectbtn-residential_complex").click(function () {
            $("#selectall-residential_complex > option").prop("selected", "selected");
            $("#selectall-residential_complex").trigger("change");
        });
        $("#deselectbtn-residential_complex").click(function () {
            $("#selectall-residential_complex > option").prop("selected", "");
            $("#selectall-residential_complex").trigger("change");
        });
    </script>
@stop