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

    <div class="mt-6">
        <livewire:datatable.master.warehouses-table />
    </div>

    @include('components.modals.confirmation', [
        'modalName' => 'delete-confirmation',
        'modalTitle' => 'Apakah Anda yakin?',
        'modalMessage' => 'Data yang berelasi dengan data ini juga akan ikut terhapus.',
        'buttonVariant' => 'primary',
        'buttonColor' => 'danger',
        'buttonText' => 'Ya, Hapus',
    ])

    <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>Nama <span class="text-red-500 ms-1">*</span></flux:label>
                <flux:input placeholder="Gudang Pusat" wire:model="form.name" autofocus autocomplete="off" />
                <flux:error name="form.name" />
            </flux:field>

            <flux:field>
                <flux:label>Deskripsi</flux:label>
                <flux:textarea placeholder="Gudang utama untuk penyimpanan semua produk." wire:model="form.description"
                    autocomplete="off" />
                <flux:error name="form.description" />
            </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>
