<?php
use Modules\Main\Models\Deal\DealStatus;
?>
<div>
    <div class="input-group mb-3 d-none">
        <button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown"
            aria-expanded="false">
            {{ (array_key_exists('status', $filter)) ? __('deal.' . $filter['status']) : 'Статус' }}
        </button>
        <ul class="dropdown-menu p-2">
            <li>
                <input wire:model.live="filter.status" type="radio" class="btn-check" name="status"
                    value="{{ DealStatus::NEW }}" id="option4" autocomplete="off" {{ (array_key_exists('status', $filter) && $filter['status'] == DealStatus::NEW) ? 'checked' : '' }}>
                <label class="" for="option4">Новые</label>
            </li>
            <li>
                <input wire:model.live="filter.status" type="radio" class="btn-check" name="status"
                    value="{{ DealStatus::MODERATION }}" id="option5" autocomplete="off" {{ (array_key_exists('status', $filter) && $filter['status'] == DealStatus::MODERATION) ? 'checked' : '' }}>
                <label class="" for="option5">На проверке</label>
            </li>
            <li>
                <input wire:model.live="filter.status" type="radio" class="btn-check" name="status"
                    value="{{ DealStatus::UNIQUE }}" id="option6" autocomplete="off" {{ (array_key_exists('status', $filter) && $filter['status'] == DealStatus::UNIQUE) ? 'checked' : '' }}>
                <label class="" for="option6">Уникальные</label>
            </li>
            <li>
                <input wire:model.live="filter.status" type="radio" class="btn-check" name="status"
                    value="{{ DealStatus::NOT_UNIQUE }}" id="option7" autocomplete="off" {{ (array_key_exists('status', $filter) && $filter['status'] == DealStatus::NOT_UNIQUE) ? 'checked' : '' }}>
                <label class="" for="option7">Не уникальные</label>
            </li>
        </ul>
        <button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown"
            aria-expanded="false">
            @if(array_key_exists('complexes', $filter))
                <span class="text-truncate">{{ $filter['complexes'][0]['name'] }}</span>
                @if(count($filter['complexes']) > 1)
                    <span>
                        + <span class="d-inline-block bg-secondary rounded-circle fs-6 text-light"
                            style="width:1.3rem;height:1.3rem">{{ count($filter['complexes']) - 1 }}</span>
                    </span>
                @endif
            @else
                Жилой комплекс
            @endif
        </button>
        <ul class="dropdown-menu">
            @foreach ($complexes as $complex)
                <li>
                    <div class="dropdown-item">
                        <input wire:change="toggleComplex({{ $complex['id'] }})" class="form-check-input" type="checkbox"
                            id="complex_selector_{{ $complex['id'] }}">
                        <label class="form-check-label" for="complex_selector_{{ $complex['id'] }}">
                            {{ $complex['name'] }}
                        </label>
                    </div>
                </li>
            @endforeach
        </ul>
        <input type="text" class="form-control" aria-label="Text input with dropdown button">
    </div>
    <div class="d-flex gap-2 flex-column flex-lg-row">
        <div class="d-flex flex-row col-12 col-lg-auto p-0" style="">
            <input wire:model.live="filter.status" type="radio" class="btn-check" name="status"
                value="{{ DealStatus::NEW }}" id="option4" autocomplete="off" {{ (array_key_exists('status', $filter) && $filter['status'] == DealStatus::NEW) ? 'checked' : '' }}>
            <label class="btn btn-secondary py-2 px-1 rounded-0 rounded-start fs-5 text-truncate" for="option4">Новые</label>
            <input wire:model.live="filter.status" type="radio" class="btn-check" name="status"
                value="{{ DealStatus::MODERATION }}" id="option5" autocomplete="off" {{ (array_key_exists('status', $filter) && $filter['status'] == DealStatus::MODERATION) ? 'checked' : '' }}>
            <label class="btn btn-secondary py-2 px-1 rounded-0 fs-5 text-truncate" for="option5">На проверке</label>
            <input wire:model.live="filter.status" type="radio" class="btn-check" name="status"
                value="{{ DealStatus::UNIQUE }}" id="option6" autocomplete="off" {{ (array_key_exists('status', $filter) && $filter['status'] == DealStatus::UNIQUE) ? 'checked' : '' }}>
            <label class="btn btn-secondary py-2 px-1 rounded-0 fs-5 text-truncate" for="option6">Уникальные</label>
            <input wire:model.live="filter.status" type="radio" class="btn-check" name="status"
                value="{{ DealStatus::NOT_UNIQUE }}" id="option7" autocomplete="off" {{ (array_key_exists('status', $filter) && $filter['status'] == DealStatus::NOT_UNIQUE) ? 'checked' : '' }}>
            <label class="btn btn-secondary py-2 px-1 rounded-0 rounded-end fs-5 text-truncate" for="option7">Не уникальные</label>
        </div>
        <div class="input-group flex-fill">
            <span class="input-group-text" id="basic-addon1">
                <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-search"
                    viewBox="0 0 16 16">
                    <path
                        d="M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001q.044.06.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1 1 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0">
                    </path>
                </svg>
            </span>
            <input wire:model.live="filter.search" type="text" class="form-control form-control-lg"
                placeholder="Поиск по имени, телефону, электронной почте">
            @if(array_key_exists('search', $filter))
                <button wire:click="removeSearchString()" class="btn btn-light m-1 btn-sm" style="z-index:1000;width:2rem;height:2rem;position:absolute;right:0;top: calc(50% - 1.2rem);">
                    <i class="bi bi-x-lg"></i>
                </button>
            @endif
        </div>
        <!-- Выбор ЖК-->
        <div class="btn-group bg-light d-flex rounded-4 ">
            <button type="button"
                class="p-0 btn bg-light text-primary border overflow-hidden w-100 rounded-start-3 pe-0"
                style="mask-image: linear-gradient(to right, black, black 90%, transparent);">
                <div class="mx-1 text-truncate fs-5">
                    @if(array_key_exists('complexes', $filter))
                        <div class="">
                            <span class="text-truncate">{{ $filter['complexes'][0]['name'] }}</span>
                            @if(count($filter['complexes']) > 1)
                                <span>
                                    + <span class="d-inline-block bg-secondary rounded-circle fs-6 text-light"
                                        style="width:1.3rem;height:1.3rem">{{ count($filter['complexes']) - 1 }}</span>
                                </span>
                            @endif
                        </div>
                    @else
                        <div class="m-2">ЖК</div>
                    @endif
                </div>
            </button>
            <button type="button" style="width:30px"
                class="btn btn-secondary dropdown-toggle dropdown-toggle-split show" data-bs-auto-close="outside" data-bs-toggle="dropdown"
                aria-expanded="false">
                <span class="visually-hidden">Toggle Dropdown</span>
            </button>
            <ul class="dropdown-menu dropdown-menu-end">
                @foreach ($complexes as $complex)
                    <li>
                        <div class="dropdown-item">
                            <input wire:change="toggleComplex({{ $complex['id'] }})" class="form-check-input"
                                type="checkbox" {{ (array_key_exists('complexes', $filter) && is_int(array_search($complex['id'], array_column($filter['complexes'], 'id'))) ? 'checked' : '')  }} id="complex_selector_{{ $complex['id'] }}">
                            <label class="form-check-label" for="complex_selector_{{ $complex['id'] }}">
                                {{ $complex['name'] }}
                            </label>
                        </div>
                    </li>
                @endforeach
                @if(1 == 2 && array_key_exists('complexes', $filter) && count($filter['complexes']) > 1)
                    <div class="text-end fs-6 text-secondary">
                        <span>Убрать все</span>
                    </div>
                @endif
            </ul>
        </div>
    </div>
</div>