<flux:main>
    <div class="flex justify-between items-center">
        <div>
            <flux:heading size="xl">{{ $pageTitle }}</flux:heading>
        </div>
        @can('create broadcast')
            <div>
                <flux:modal.trigger name="form-modal">
                    <flux:button variant="primary" class="text-sm"
                        wire:click="$dispatch('modal:open', {method: 'create', 'modalTitle': 'Tambah Broadcast'})">Tambah
                    </flux:button>
                </flux:modal.trigger>
            </div>
        @endcan
    </div>

    <div class="mt-6">
        <livewire:datatable.studio.information.broadcasts-table />
    </div>

    @include('components.confirmation.delete')
    <flux:modal name="form-modal" class="w-[95%] max-w-sm md:max-w-xl mx-auto" @close="closeModal('form-modal')">
        <div class="p-4 space-y-6">
            <flux:heading size="lg">{{ $modalTitle }}</flux:heading>

            <flux:field>
                <flux:label>Judul <span class="text-red-500 ms-1">*</span></flux:label>
                <flux:input placeholder="Yakin nggak mau coba aroma ini? 🌸✨"
                    wire:model.live.debounce.500ms="form.title" autofocus autocomplete="off" />
                <flux:error name="form.title" />
            </flux:field>

            <flux:field>
                <flux:label>Body <span class="text-red-500 ms-1">*</span></flux:label>
                <flux:textarea placeholder="Coba cek sekarang… siapa tahu cocok banget 😌🍃"
                    wire:model.live.debounce.500ms="form.body" autocomplete="off" rows="2" />
                <flux:error name="form.body" />
            </flux:field>

            <flux:field>
                <flux:label>Audiensi <span class="text-red-500 ms-1">*</span></flux:label>
                <flux:select variant="listbox" multiple searchable placeholder="Pilih Audiensi"
                    wire:model.live.debounce.500ms="form.role_ids">
                    <flux:select.option wire:click="selectAllRoles" wire:ignore>Pilih Semua
                    </flux:select.option>
                    <flux:select.option wire:click="deselectAllRoles" wire:ignore>Hapus Semua
                    </flux:select.option>
                    @foreach ($roles as $key => $value)
                        <flux:select.option value="{{ $key }}">{{ $value }}
                        </flux:select.option>
                    @endforeach
                </flux:select>
                <flux:error name="form.role_ids" />
            </flux:field>

            <div class="flex">
                <flux:spacer />
                <flux:button variant="primary" class="sm:w-auto cursor-pointer" wire:click="{{ $method }}">
                    Simpan
                </flux:button>
            </div>
        </div>
    </flux:modal>
</flux:main>
