@php
$latAttributes = [
    'id' => $id . '_lat',
    'class' => 'form-control',
    'maxlength' => 50,
    'data-toggle' => (isset($errors) && $errors->has($errorLatKey) ? 'tooltip': null),
    'title' => (isset($errors) && $errors->has($errorLatKey) ? $errors->first($errorLatKey): null)
];
$lngAttributes = [
    'id' => $id . '_lng',
    'class' => 'form-control',
    'maxlength' => 50,
    'data-toggle' => (isset($errors) && $errors->has($errorLngKey) ? 'tooltip': null),
    'title' => (isset($errors) && $errors->has($errorLngKey) ? $errors->first($errorLngKey): null)
];
if (!$enabled) {
    $latAttributes['disabled'] = true;
    $lngAttributes['disabled'] = true;
}
@endphp
<div id="location-picker-{{$id}}" class="form-field-location is-versionable {{ $blocksMode ? "blocks-mode--$blocksMode" : 'blocks-mode--hide' }} form-group{{ $parentHidden ? ' parent-hidden' : '' }}" style="{{ !empty($hidden) ? 'display:none' : '' }}">
    {!! html()->label(ucfirst($label))->for($id)->attributes(['class' => 'control-label']) !!}
    <div class="well">
        @if($enabled)
            <div class="input-group location-picker-address-wrapper">
                {{ html()->text($name . '_address', '')->attributes([
                    'id' => $id . '_address',
                    'class' => 'form-control',
                    'maxlength' => 150,
                    'placeholder' => trans("backend.find_address")
                ]) }}
                <span class="input-group-btn">
                    <button name="btn-search-address" class="btn btn-default" type="button">OK</button>
                </span>
            </div>
        @endif
        <div class="location-map"></div>
        <div class="row location-coordinates">
            <div class="col-sm-6">
                <div class="form-group @error($errorLatKey) has-error @enderror">
                    {!! html()->label(trans("backend.latitude"))->for($id . '_lat')->attributes(['class' => 'control-label pull-left']) !!}
                    {{ html()->text($name . '[lat]', $value["lat"])->attributes($latAttributes) }}
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group @error($errorLngKey) has-error @enderror">
                    {!! html()->label(trans("backend.longitude"))->for($id . '_lng')->attributes(['class' => 'control-label pull-left']) !!}
                    {{ html()->text($name . '[lng]', $value["lng"])->attributes($lngAttributes) }}
                </div>
            </div>
        </div>
        {!! html()->hidden($name . '[zoom]')->value($value["zoom"])->attributes(['id' => $id . '_zoom']) !!}
    </div>
    @if(!empty($info))
        <span id="helpBlock" class="help-block">{{ $info }}</span>
    @endif
</div>

<script>
    $(function(){
        new Eae.View.BackendLocationPicker({
            el: $("#generic_form_{{getRequestContext('generic_form_timestamp')}} #location-picker-{{$id}}"),
            fieldId: '{{ $id }}',
            required: @json($required),
            enabled: @json($enabled),
            parent:  {!! empty($parent) ? 'false': json_encode($parent) !!}
        });
    });
</script>
