<flux:main>
    <div class="flex justify-between items-center">
        <div>
            <flux:heading size="xl">{{ $pageTitle }}</flux:heading>
        </div>
        <div>
            <flux:button href="{{ route('studio.loyalty.voucher.index') }}" wire:navigate.hover class="text-sm">
                Kembali
            </flux:button>
        </div>
    </div>

    <div class="mt-6">
        <div class="flex flex-col gap-4">
            <div class="flex flex-col lg:flex-row gap-4">
                <div class="w-full lg:w-3/4 space-y-4">
                    <div class="grid grid-cols-1 gap-4 lg:grid-cols-2 items-start">
                        <div class="col-span-1 lg:col-span-2">
                            <flux:card class="space-y-6 p-6">
                                <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                                    <flux:field>
                                        <flux:label>Nama <span class="text-red-500 ms-1">*</span></flux:label>
                                        <flux:input placeholder="SELAMAT DATANG"
                                            wire:model.live.debounce.500ms="form.name" autofocus autocomplete="off" />
                                        <flux:error name="form.name" />
                                    </flux:field>

                                    <flux:field>
                                        <flux:label>Kode <span class="text-red-500 ms-1">*</span></flux:label>
                                        <flux:input placeholder="WELCOME" wire:model.live.debounce.500ms="form.code"
                                            autocomplete="off" copyable
                                            oninput="this.value = this.value.toUpperCase()" />
                                        <flux:error name="form.code" />
                                    </flux:field>

                                    <div class="lg:col-span-2">
                                        <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
                                            <flux:field>
                                                <flux:label>Min. Belanja</flux:label>
                                                <flux:input.group>
                                                    <flux:input.group.prefix>Rp</flux:input.group.prefix>
                                                    <flux:input placeholder="10.000"
                                                        x-mask:dynamic="$money($input, ',')"
                                                        wire:model.live.debounce.500ms="form.min_purchase"
                                                        autocomplete="off" />
                                                </flux:input.group>
                                                <flux:error name="form.min_purchase" />
                                            </flux:field>

                                            <flux:input label="Kuota" placeholder="1"
                                                wire:model.live.debounce.500ms="form.quota"
                                                x-mask:dynamic="$money($input, ',')" autocomplete="off" />

                                            <flux:input label="Batas Per Customer" placeholder="1"
                                                wire:model.live.debounce.500ms="form.limit_per_user"
                                                x-mask:dynamic="$money($input, ',')" autocomplete="off" />
                                        </div>
                                    </div>

                                    <flux:field>
                                        <flux:label>Tanggal Mulai <span class="text-red-500 ms-1">*</span></flux:label>
                                        <flux:date-picker with-today wire:model.live.debounce.500ms="form.start_date"
                                            placeholder="Pilih Tanggal" autocomplete="off" locale="id-ID" />
                                        <flux:error name="form.start_date" />
                                    </flux:field>

                                    <flux:date-picker with-today label="Tanggal Selesai"
                                        wire:model.live.debounce.500ms="form.end_date" placeholder="Pilih Tanggal"
                                        autocomplete="off" locale="id-ID" />
                                </div>
                            </flux:card>
                        </div>
                    </div>
                </div>

                <div class="w-full lg:w-1/3 space-y-4">
                    <flux:card class="space-y-2 p-6">
                        <flux:field>
                            <flux:label>Jumlah Diskon <span class="text-red-500 ms-1">*</span></flux:label>
                            <flux:radio.group wire:model.live="form.type" variant="buttons" class="w-full *:flex-1">
                                @foreach (\App\Enums\VoucherType::cases() as $item)
                                    <flux:radio value="{{ $item->value }}">
                                        {{ $item->label() }}
                                    </flux:radio>
                                @endforeach
                            </flux:radio.group>
                            <flux:error name="form.type" />
                        </flux:field>

                        <flux:field>
                            <flux:label>Jumlah Diskon <span class="text-red-500 ms-1">*</span></flux:label>
                            <flux:input.group>
                                @if ($form->type == \App\Enums\VoucherType::FIXED->value)
                                    <flux:input.group.prefix>Rp</flux:input.group.prefix>
                                    <flux:input placeholder="10.000" x-mask:dynamic="$money($input, ',')"
                                        wire:model.live.debounce.500ms="form.discount_amount" autocomplete="off" />
                                @else
                                    <flux:input placeholder="5" wire:model.live.debounce.500ms="form.discount_amount"
                                        autocomplete="off" />
                                    <flux:input.group.suffix>%</flux:input.group.suffix>
                                @endif
                            </flux:input.group>
                            <flux:error name="form.discount_amount" />
                        </flux:field>

                        @if ($form->type == \App\Enums\VoucherType::PERCENTAGE->value)
                            <flux:field>
                                <flux:label>Maks. Diskon <span class="text-red-500 ms-1">*</span></flux:label>
                                <flux:input.group>
                                    <flux:input.group.prefix>Rp</flux:input.group.prefix>
                                    <flux:input placeholder="10.000"
                                        x-mask:dynamic="$money($input, ',')"
                                        wire:model.live.debounce.500ms="form.max_discount" autocomplete="off" />
                                </flux:input.group>
                                <flux:error name="form.max_discount" />
                            </flux:field>
                        @endif
                    </flux:card>

                    <flux:card class="space-y-6 p-6">
                        <flux:field>
                            <flux:label>Outlet <span class="text-red-500 ms-1">*</span></flux:label>
                            <flux:select variant="listbox" multiple searchable placeholder="Pilih Outlet"
                                wire:model.live.debounce.500ms="form.outlet_ids">
                                <flux:select.option wire:click="selectAllOutlets" wire:ignore>Pilih Semua
                                </flux:select.option>
                                <flux:select.option wire:click="deselectAllOutlets" wire:ignore>Hapus Semua
                                </flux:select.option>
                                @foreach ($outlets as $key => $value)
                                    <flux:select.option value="{{ $key }}">{{ $value }}
                                    </flux:select.option>
                                @endforeach
                            </flux:select>
                            <flux:error name="form.outlet_ids" />
                        </flux:field>
                    </flux:card>
                </div>
            </div>

            <div class="flex justify-start">
                <flux:button variant="primary" class="sm:w-auto cursor-pointer" wire:click="save">
                    Simpan
                </flux:button>
            </div>
        </div>
    </div>
</flux:main>
