<div class="row w-100 px-2 m-0">
    <div class="col-12 px-0 py-1 px-2">
        <b>
            <span class="float-left">{{ trans('visiosoft.module.location::field.address.name') }}</span>
        </b>
        {% set defaultCountry = setting_value('visiosoft.module.location::default_country') %}
        {% set selectedCountry =  app.request.get('country') %}
        <a href="#" class="a-sahibinden-type selected-country filter-country-btn float-right">
            {% set countryValue = '' %}
            {% if selectedCountry %}
                {% set countryName = getCountry(selectedCountry).name %}
                {% set countryValue = defaultCountry == selectedCountry ? '' : selectedCountry %}
            {% elseif defaultCountry %}
                {% set countryName = getCountry(defaultCountry).name %}
                {% set countryValue = defaultCountry %}
            {% else %}
                {% set countryName = trans("visiosoft.module.location::field.country.name") %}
            {% endif %}
            <small>{{ countryName }}</small>
        </a>
        <input name="country" value="{{ countryValue }}" type="hidden">
    </div>
    <div class="col-12 px-0 py-1">
        <button type="button" class="btn btn-default border border-1 w-100 filter-city-btn" data-toggle="modal"
                data-parent="">
            <span class="float-left">{{ trans("visiosoft.module.location::field.city.name") }}</span>
            <i class="fas fa-sort-down float-right"></i>
        </button>
        {% set citySlug = null %}
        {% set pathInfo = app.request.pathinfo|split('/') %}
        {% if pathInfo|length is same as(4) %}
            {% set citySlug = entries('location', 'cities').findBy('slug', pathInfo[3]) %}
            {% set selected_cities_name = [getCity(citySlug.id).name] %}
        {% else %}
            {% set selected_cities = params.param['city'] %}
            {% set selected_cities_name = [] %}
            {% for selected_city in selected_cities[0]|split(',') %}
                {% set selected_cities_name = selected_cities_name|merge([getCity(selected_city|trim(',')).name]) %}
            {% endfor %}
        {% endif %}
        <div class="text-muted selected-city">
            <small>{{ selected_cities_name|join(',') }}</small>
        </div>
        <input name="city[]" type="hidden"
               value="{% if citySlug %}{{ citySlug.id }}{% else %}{{ params.param['city']|join(',') }}{% endif %}">
    </div>
    <div class="col-12 px-0 py-1">
        <button type="button" class="btn btn-default border border-1 w-100 filter-district-btn" data-toggle="modal"
                data-parent="">
            <span class="float-left">{{ trans("visiosoft.module.location::field.district.name") }}</span>
            <i class="fas fa-sort-down float-right"></i>
        </button>
        {% set selected_districts = app.request.get('district') %}
        {% set selected_districts_name = [] %}
        {% for selected_district in selected_districts[0]|split(',') %}
            {% set selected_districts_name = selected_districts_name|merge([getDistrict(selected_district|trim(',')).name]) %}
        {% endfor %}
        <div class="text-muted selected-district">
            <small>{{ selected_districts_name|join(',') }}</small>
        </div>
        <input name="district[]" value="{{ app.request.get('district')|join(',') }}" type="hidden">
    </div>
    <div class="col-12 px-0 py-1">
        <button type="button" class="btn btn-default border border-1 w-100 filter-neighborhood-btn" data-toggle="modal"
                data-parent="">
            <span class="float-left">{{ trans("visiosoft.module.location::field.neighborhood.name") }}</span>
            <i class="fas fa-sort-down float-right"></i>
        </button>
        {% set selected_neighborhoods = app.request.get('neighborhood') %}
        {% set selected_neighborhoods_name = [] %}
        {% for selected_neighborhood in selected_neighborhoods[0]|split(',') %}
            {% set selected_neighborhoods_name = selected_neighborhoods_name|merge([getNeighborhood(selected_neighborhood|trim(',')).name]) %}
        {% endfor %}
        <div class="text-muted selected-neighborhood">
            <small>{{ selected_neighborhoods_name|join(',') }}</small>
        </div>
        <input name="neighborhood[]" value="{{ app.request.get('neighborhood')|join(',') }}" type="hidden">
    </div>
    <div class="col-12 px-0 py-1">
        <button type="button" class="btn btn-default border border-1 w-100 filter-village-btn" data-toggle="modal"
                data-parent="">
            <span class="float-left">{{ trans("visiosoft.module.location::field.village.name") }}</span>
            <i class="fas fa-sort-down float-right"></i>
        </button>
        {% set selected_villages = app.request.get('village') %}
        {% set selected_villages_name = [] %}
        {% for selected_village in selected_villages[0]|split(',') %}
            {% set selected_villages_name = selected_villages_name|merge([getVillage(selected_village|trim(',')).name]) %}
        {% endfor %}
        <div class="text-muted selected-village">
            <small>{{ selected_villages_name|join(',') }}</small>
        </div>
        <input name="village[]" value="{{ app.request.get('village')|join(',') }}" type="hidden">
    </div>
</div>

<div class="modal-content position-absolute filter-location-modal" style="z-index: 9999;display: none">
    <div class="modal-header">
        <input type="text" id="searchLocation" class="form-control"
               placeholder="{{ trans('visiosoft.module.location::message.placeholder') }}">
        <button type="button" class="close filter-modal-close">
            <span aria-hidden="true">&times;</span>
        </button>
    </div>
    <div class="modal-body filter-location-body">
        <div class="loading"></div>
        <ul class="list-unstyled countries"></ul>
        <ul class="list-unstyled cities"></ul>
        <ul class="list-unstyled districts"></ul>
        <ul class="list-unstyled neighborhoods"></ul>
        <ul class="list-unstyled village"></ul>
    </div>
</div>
<div class="filter-location-back" style="display: none"></div>

<script>
    var null_msg = "{{ trans('visiosoft.module.location::message.null_msg') }}!"
</script>
