<div>
    <div>
        <button wire:click="back"
            class="btn border-0 icon-link icon-link-hover fs-5 mb-3 text-decoration-none text-primary"
            style="--bs-icon-link-transform: translate3d(-.125rem, 0, 0);" href="#">
            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"
                class="bi bi-chevron-left" viewBox="0 0 16 16">
                <path fill-rule="evenodd"
                    d="M11.354 1.646a.5.5 0 0 1 0 .708L5.707 8l5.647 5.646a.5.5 0 0 1-.708.708l-6-6a.5.5 0 0 1 0-.708l6-6a.5.5 0 0 1 .708 0" />
            </svg>
            {{ $company->name }}
        </button>
        <div class="fs-5 bg-light p-0 m-0 border border-1 rounded-4 py-3">
            <table class="table m-0 table-striped-columns">
                <thead>
                    <tr scope="col">
                        <th>Агент</th>
                        @foreach ($complexes as $complex)
                            <th>
                                {{ $complex->name }}
                                <div>
                                    {{ $complex->city->name }}
                                </div>
                                <div>
                                    @php($compPayment = $company->getPaymentable($complex))
                                    <div class="dropdown">
                                        <a class="btn bg-secondary-subtle btn-sm text-truncate" href="#"
                                            role="button" data-bs-toggle="dropdown" aria-expanded="false">
                                            @if ($compPayment->value === null)
                                                Не установлено
                                            @elseif($compPayment->value == -1)
                                                Наследовать
                                            @else
                                                {{ $compPayment->value }} %
                                            @endif
                                            <i class="bi bi-three-dots-vertical"></i>
                                        </a>

                                        <ul class="dropdown-menu">
                                            <li>
                                                <a class="dropdown-item " href="#">
                                                    <span class="badge text-dark">Введите размер вознаграждения:
                                                    </span>
                                                    <div class="input-group mb-3">
                                                        <span class="input-group-text" id="basic-addon1">
                                                            <svg xmlns="http://www.w3.org/2000/svg" width="20"
                                                                height="20" fill="currentColor" class="bi bi-percent"
                                                                viewBox="0 0 16 16">
                                                                <path
                                                                    d="M13.442 2.558a.625.625 0 0 1 0 .884l-10 10a.625.625 0 1 1-.884-.884l10-10a.625.625 0 0 1 .884 0M4.5 6a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3m0 1a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5m7 6a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3m0 1a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5" />
                                                            </svg>
                                                        </span>
                                                        <input class="form-control" type="text"
                                                            placeholder="Вознаграждение"
                                                            value="{{ $compPayment->value }}"
                                                            wire:model.lazy = "newValue"
                                                            wire:keydown.enter="setPaymentValueForCompany({{ $company->id }}, {{ $complex->id }})">
                                                    </div>
                                                </a>
                                            </li>
                                            @if ($compPayment->value)
                                                <li>
                                                    <hr class="dropdown-divider">
                                                </li>
                                                <li>
                                                    <button class="dropdown-item"
                                                        wire:click="setPaymentForAllAgentOfCompany({{ $company->id }}, {{ $complex->id }})">Установить
                                                        {{ $compPayment->value }}
                                                        % для всех агентов</button>
                                                </li>
                                            @endif
                                        </ul>
                                    </div>
                                </div>
                            </th>
                        @endforeach
                    </tr>
                </thead>
                <tbody class=" ">
                    @foreach ($agents as $agent)
                        <tr scope="row">
                            <td class="align-middle">
                                {{ $agent->user->name }}
                            </td>
                            @foreach ($complexes as $complex)
                                @php($paymentable = $agent->getPaymentable($complex))
                                <td>
                                    @if ($paymentable->value == null)
                                        <div class="dropdown">
                                            <button class="btn btn-light" type="button" data-bs-toggle="dropdown"
                                                aria-expanded="false">
                                                Не установлено
                                            </button>
                                            <ul class="dropdown-menu">
                                                <li>
                                                    <a class="dropdown-item " href="#">
                                                        <span class="badge text-dark">Введите размер вознаграждения:
                                                        </span>
                                                        <div class="input-group mb-3">
                                                            <span class="input-group-text" id="basic-addon1">
                                                                <svg xmlns="http://www.w3.org/2000/svg" width="20"
                                                                    height="20" fill="currentColor"
                                                                    class="bi bi-percent" viewBox="0 0 16 16">
                                                                    <path
                                                                        d="M13.442 2.558a.625.625 0 0 1 0 .884l-10 10a.625.625 0 1 1-.884-.884l10-10a.625.625 0 0 1 .884 0M4.5 6a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3m0 1a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5m7 6a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3m0 1a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5" />
                                                                </svg>
                                                            </span>
                                                            <input class="form-control" type="text"
                                                                placeholder="Вознаграждение"
                                                                value="{{ $paymentable->value }}"
                                                                wire:model = "newValue"
                                                                wire:keydown.enter="setPaymentValueForAgent({{ $agent->id }}, {{ $complex->id }})">
                                                        </div>
                                                    </a>
                                                </li>
                                                <li>
                                                    <hr class="dropdown-divider">
                                                </li>
                                                <li><button class="dropdown-item"
                                                        wire:click="setPaymentAsParentForAgent({{ $agent->id }}, {{ $complex->id }})">Наследовать</button>
                                                </li>
                                            </ul>
                                        </div>
                                    @elseif($paymentable->value == -1)
                                        <div class="dropdown">
                                            <button class="btn btn-light" type="button" data-bs-toggle="dropdown"
                                                aria-expanded="false">
                                                Наследовать
                                            </button>
                                            <ul class="dropdown-menu">
                                                <li>
                                                    <a class="dropdown-item " href="#">
                                                        <span class="badge text-dark">Введите размер вознаграждения:
                                                        </span>
                                                        <div class="input-group mb-3">
                                                            <span class="input-group-text" id="basic-addon1">
                                                                <svg xmlns="http://www.w3.org/2000/svg" width="20"
                                                                    height="20" fill="currentColor"
                                                                    class="bi bi-percent" viewBox="0 0 16 16">
                                                                    <path
                                                                        d="M13.442 2.558a.625.625 0 0 1 0 .884l-10 10a.625.625 0 1 1-.884-.884l10-10a.625.625 0 0 1 .884 0M4.5 6a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3m0 1a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5m7 6a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3m0 1a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5" />
                                                                </svg>
                                                            </span>
                                                            <input class="form-control" type="text"
                                                                placeholder="Вознаграждение"
                                                                value="{{ $paymentable->value }}"
                                                                wire:model = "newValue"
                                                                wire:keydown.enter="setPaymentValueForAgent({{ $agent->id }}, {{ $complex->id }})">
                                                        </div>
                                                    </a>
                                                </li>
                                                <li>
                                                    <hr class="dropdown-divider">
                                                </li>
                                                <li><button class="dropdown-item"
                                                        wire:click="unsetPaymentForAgent({{ $agent->id }}, {{ $complex->id }})">Без
                                                        вознаграждения</button></li>
                                            </ul>
                                        </div>
                                    @else
                                        <div class="dropdown">
                                            <button class="btn btn-light" type="button" data-bs-toggle="dropdown"
                                                aria-expanded="false">
                                                {{ $paymentable->value }} %
                                            </button>
                                            <ul class="dropdown-menu">
                                                <li>
                                                    <a class="dropdown-item " href="#">
                                                        <span class="badge text-dark">Введите размер вознаграждения:
                                                        </span>
                                                        <div class="input-group mb-3">
                                                            <span class="input-group-text" id="basic-addon1">
                                                                <svg xmlns="http://www.w3.org/2000/svg" width="20"
                                                                    height="20" fill="currentColor"
                                                                    class="bi bi-percent" viewBox="0 0 16 16">
                                                                    <path
                                                                        d="M13.442 2.558a.625.625 0 0 1 0 .884l-10 10a.625.625 0 1 1-.884-.884l10-10a.625.625 0 0 1 .884 0M4.5 6a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3m0 1a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5m7 6a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3m0 1a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5" />
                                                                </svg>
                                                            </span>
                                                            <input class="form-control" type="text"
                                                                placeholder="Вознаграждение"
                                                                value="{{ $paymentable->value }}"
                                                                wire:model = "newValue"
                                                                wire:keydown.enter="setPaymentValueForAgent({{ $agent->id }}, {{ $complex->id }})">
                                                        </div>
                                                    </a>
                                                </li>
                                                <li>
                                                    <hr class="dropdown-divider">
                                                </li>
                                                <li><button class="dropdown-item"
                                                        wire:click="unsetPaymentForAgent({{ $agent->id }}, {{ $complex->id }})">Без
                                                        вознаграждения</button>
                                                </li>
                                                <li><button class="dropdown-item"
                                                        wire:click="setPaymentAsParentForAgent({{ $agent->id }}, {{ $complex->id }})">Наследовать</button>
                                                </li>
                                            </ul>
                                        </div>
                                    @endif
                                </td>
                            @endforeach
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
    </div>
</div>
