@php($title = 'Приглашения агентов')
@extends('layouts.app')
@section('content')
    <div class="d-flex mb-3 sticky-top bg-light rounded-3">
        <div class="p-2 w-100"></div>
        <div class="p-2 flex-shrink-1">
            <form class="" method="post" action="{{ route('company.invites.create', ['company' => 1]) }}">
                @csrf
                <input class="btn btn-primary" type="submit" value="Создать приглашение" />
            </form>
        </div>
    </div>

    <h5>Доступные агентства</h5>
    <div class="row g-2 w-100">
        @foreach ($companies as $company)
            <a href="{{ route('company.invites', ['company' => $company]) }}"
                class="p-2 bg-light rounded icon-link icon-link-hover w-100 hstack gap-2 text-decoration-none">
                <span class="col-8 text-dark">{{ $company->name }}</span>
                <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"
                    class="bi bi-chevron-right ms-auto" viewBox="0 0 16 16">
                    <path fill-rule="evenodd"
                        d="M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708" />
                </svg>
            </a>

        @endforeach
    </div>
    <script>
        const copyBtns = document.querySelectorAll('.copy-invite-btn');
        Array.from(copyBtns).forEach(btn => {
            btn.addEventListener('click', function (event) {
                targetId = '#' + event.target.dataset.target;
                navigator.clipboard.writeText(document.querySelector(targetId).value)
                    .then(() => {
                        alert('Ссылка скопирована в буфер обмена');
                    })
                    .catch(error => {
                        console.error(`Ошибка копирования: ${error}`)
                    });
            });
        });
    </script>
    </div>
@endsection