<div class="">
    <div id="{{ $containerId }}">
        <input type="hidden" name="plan7_apa" value="{{ ($room) ? $room['id'] : '' }}">
        <!-- Button trigger modal -->
        <div class="d-flex flex-wrap justify-content-between align-self-start gap-2">
            @if($room)
                <div class="text-primary">
                    <div class="text-uppercase fw-bold">
                        {{ (($room['type'] == 0) ? $room['room'] . ' комн. ' . mb_strtolower($this->types[$room['type']]) : $this->types[$room['type']])  }}
                    </div>
                    <div class="d-flex flex-wrap gap-2 fs-6">
                        <div class="badge text-bg-secondary">Помещение: {{ $room['name'] }}</div>
                        <div class="badge text-bg-secondary">Площадь: {{ $room['area'] }}</div>
                        <div class="badge text-bg-secondary">Этаж: {{ $room['level'] }}</div>
                    </div>
                </div>
            @endif
            <div>
                <button type="button" class="btn btn-primary" wire:click="start()" wire:loading.class="opacity-50" wire:target="load" class="btn btn-primary"
                    onclick="plan7SelectorModal = new bootstrap.Modal(document.getElementById('plan7_selector_modal_{{ $complexId }}'), {});plan7SelectorModal.show()">
                    @if($room)
                        Изменить
                    @else
                        Выбрать помещение
                    @endif
                </button>
            </div>
        </div>



        <!-- Modal -->
        <div class="modal fade" wire:ignore.self id="plan7_selector_modal_{{ $complexId }}" tabindex="-1"
            aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-dialog-scrollable  modal-xl modal-fullscreen-lg-down">
                <div class="modal-content">
                    <div class="modal-header">
                        <h1 class="modal-title fs-5 text-dark" id="exampleModalLabel">Выбор помещения в {{ $complexName }}</h1>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                    </div>
                    <div class="modal-body">

                        @if($room)
                            <div wire:loading.class="opacity-50" class="d-flex flex-wrap gap-3">
                                <div class="col-12 col-md-7">
                                    @if(array_key_exists($room['pla'], $allObjects['pla']))
                                        <img src="{{ $allObjects['pla'][$room['pla']]['pla'] }}" class="img-fluid rounded-start"
                                            alt="...">
                                    @endif
                                </div>
                                <div class="col px-3">
                                    <h3 class="fw-bold mb-3 text-uppercase text-primary">
                                        {{ (($room['type'] == 0) ? $room['room'] . ' комн. ' . mb_strtolower($this->types[$room['type']]) : $this->types[$room['type']])  }}
                                    </h3>
                                    <div class="d-flex flex-wrap gap-3">
                                        <div class="hstack gap-3 w-100">
                                            <div class="d-flex flex-column w-50 p-2 bg-light border border-1 rounded-4">
                                                <span class="text-secondary">Помещение</span><span
                                                    class="fs-3 text-dark">{{ $room['name'] }}</span>
                                            </div>
                                            <div class="d-flex flex-column w-50 p-2 bg-light border border-1 rounded-4">
                                                <span class="text-secondary">Этаж</span><span
                                                    class="fs-3 text-dark">{{ $room['level'] }}</span>
                                            </div>
                                        </div>
                                        <div class="d-flex flex-column w-100 p-2 bg-light border border-1 rounded-4">
                                            <span class="text-secondary">Площадь</span><span
                                                class="fs-3 text-dark">{{ $room['area'] }} м<sup>2</sup></span>
                                        </div>
                                        <div class="d-flex flex-column w-100 p-2 bg-light border border-1 rounded-4">
                                            <span class="text-secondary">Стоимость</span><span
                                                class="fs-3 text-dark">{{ ($room['summ']) ? number_format($room['summ'], 0, '', ' ') . ' р.' : '' }}</span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        @endif
                        @if(!$room)
                            <div class="d-flex gap-2 mb-3 flex-column flex-xl-row">
                                <div class="col-12 col-xl-4 p-2 rounded-4 bg-light border hstack gap-2">
                                    <div class="flex-fill">
                                        <label>Дом/строение:</label>
                                        <div>
                                            <select wire:loading.attr="disabled" class="form-select"
                                                wire:model.change="filter.bs">
                                                <option></option>
                                                @foreach($allObjects['values']['bs'] as $bs)
                                                    <option value="{{ $bs['id'] }}">{{ $bs['name'] }} </option>
                                                @endforeach
                                            </select>
                                        </div>
                                    </div>
                                    <div class="flex-fill">
                                        <label>Тип помещения:</label>
                                        <div>
                                            <select wire:loading.attr="disabled" class="form-select"
                                                wire:model.change="filter.type">
                                                <option></option>
                                                @foreach($summary as $typeSummary)
                                                    @if(array_key_exists('type', $typeSummary))
                                                        <option value="{{ $typeSummary['type'] }}">
                                                            {{ $types[$typeSummary['type']] }}
                                                        </option>
                                                    @endif
                                                @endforeach
                                            </select>
                                        </div>
                                    </div>
                                </div>
                                @if(array_key_exists('type', $filter))
                                    @foreach($summary as $typeSummary)
                                        @if(array_key_exists('type', $typeSummary) && $typeSummary['type'] == $filter['type'])
                                            <div class="d-flex flex-fill gap-2 flex-column flex-sm-row">
                                                <div class="p-2 rounded-4 bg-light border">
                                                    <label>Площадь:</label>
                                                    <div class="input-group">
                                                        <span class="input-group-text">от</span>
                                                        <input wire:loading.attr="disabled" type="number"
                                                            wire:model.live.debounce.500ms="filter.min_area" class="form-control"
                                                            placeholder="{{ $typeSummary['min_area'] }}">
                                                        <span class="input-group-text">до</span>
                                                        <input wire:loading.attr="disabled" type="number"
                                                            wire:model.live.debounce.500ms="filter.max_area" class="form-control"
                                                            placeholder="{{ $typeSummary['max_area'] }}">
                                                    </div>
                                                </div>
                                                <div class="p-2 rounded-4 bg-light border">
                                                    <label>Стоимость:</label>
                                                    <div class="input-group">
                                                        <span class="input-group-text">от</span>
                                                        <input wire:loading.attr="disabled"
                                                            wire:model.live.debounce.500ms="filter.min_price" type="number"
                                                            class="form-control"
                                                            placeholder="{{ number_format($typeSummary['min_price'], 0, '', ' ') . ' р.' }}">
                                                        <span class="input-group-text">до</span>
                                                        <input wire:loading.attr="disabled"
                                                            wire:model.live.debounce.500ms="filter.max_price" type="number"
                                                            class="form-control"
                                                            placeholder="{{ number_format($typeSummary['max_price'], 0, '', ' ') . ' р.' }}">
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="d-none p-2 rounded-4 mb-3 bg-light border">
                                                <label>На каком этаже:</label>
                                                <div>
                                                    @foreach($summary as $typeSummary)
                                                        @if(array_key_exists('type', $typeSummary) && $typeSummary['type'] == $filter['type'])
                                                            @foreach($typeSummary['floor'] as $floor)

                                                            @endforeach
                                                        @endif
                                                    @endforeach
                                                </div>
                                            </div>
                                        @endif
                                    @endforeach
                                @endif
                            </div>
                            @if(count($filter) && count($objs))
                                <div class="text-dark">Всего помещений: {{ count($objs) }}</div>
                            @endif
                            @if(!count($objs))
                                <div wire:loading.remove class="p-5 text-secondary w-100 text-center fs-3">
                                    Нет помещений для отображения по выбранным параметрам
                                </div>
                            @endif
                            <div wire:loading.class="opacity-50" class="d-flex flex-wrap">
                                @foreach($objs as $obj)
                                    <div class="p-2 col-12 col-sm-6 col-md-4 plan7-selector__container">
                                        @if($obj['mode'] == 'bs')
                                            <div class="card" wire:click="setHouse({{ $obj['id'] }})">
                                                <div class="card-body">
                                                    <h5 class="card-title">{{ $obj['name'] }}</h5>
                                                    <h6 class="card-subtitle mb-2 text-body-secondary">Секция/дoм</h6>
                                                    <p class="card-text"></p>
                                                    <a href="#" class="card-link">Выбрать</a>
                                                </div>
                                            </div>
                                        @elseif($obj['mode'] == 'room')
                                            <div wire:click="setRoom({{ $obj['id'] }})" class="card plan7-selector__item" style="">
                                                <div class="row g-0">
                                                    <div class="col-md-8">
                                                        <div class="card-body">
                                                            <h5 class="card-title">
                                                                {{ (($obj['type'] == 0) ? $obj['room'] . ' комн. ' . mb_strtolower($this->types[$obj['type']]) : $this->types[$obj['type']])  }}
                                                            </h5>
                                                            <p class="card-text">
                                                            <div>Площадь: {{ $obj['area'] }}</div>
                                                            <div>Помещение: {{ $obj['name'] }}</div>
                                                            <div>Этаж: {{ $obj['level'] }}</div>
                                                            </p>
                                                            <h5 class="card-text">
                                                                {{ ($obj['summ']) ? number_format($obj['summ'], 0, '', ' ') . ' р.' : '' }}
                                                            </h5>
                                                        </div>
                                                    </div>
                                                    <div
                                                        class="col-md-4 d-none d-sm-flex align-items-center overflow-hidden plan7-selector__image">
                                                        <img src="{{ array_key_exists($obj['pla'], $allObjects['pla']) ? $allObjects['pla'][$obj['pla']]['pla'] : '...' }}"
                                                            style="" class="img-fluid rounded" alt="...">
                                                    </div>
                                                </div>
                                            </div>
                                        @endif
                                    </div>
                                @endforeach
                            </div>
                        @endif
                    </div>
                    @if($room)
                        <div class="modal-footer">
                            <button wire:click="unsetRoom()" wire:loading.attr="disabled" type="button"
                                class="btn btn-secondary">Выбрать другое</button>
                            <button wire:click="done()" wire:loading.attr="disabled" type="button" class="btn btn-primary"
                                data-bs-dismiss="modal">Выбрать и
                                закрыть</button>
                        </div>
                    @endif
                </div>
            </div>
        </div>
    </div>
</div>