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

    <div class="mt-6">
        <livewire:datatable.studio.loyalty.customers-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>Nama <span class="text-red-500 ms-1">*</span></flux:label>
                <flux:input placeholder="Yoga Pangestu" wire:model.live.debounce.500ms="form.name" autofocus
                    autocomplete="off" />
                <flux:error name="form.name" />
            </flux:field>

        <flux:input label="Nomor Telepon" placeholder="0821 xxxx xxxx" mask="9999 9999 99999"
                wire:model.live.debounce.500ms="form.phone_number" autocomplete="off" />

            <flux:field>
                <flux:label>Jenis Kelamin <span class="text-red-500 ms-1">*</span></flux:label>
                <flux:radio.group wire:model.live="form.gender" variant="buttons" class="w-full *:flex-1">
                    @foreach (\App\Enums\Gender::cases() as $gender)
                        <flux:radio value="{{ $gender->value }}">
                            {{ $gender->label() }}
                        </flux:radio>
                    @endforeach
                </flux:radio.group>
                <flux:error name="form.gender" />
            </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>
