<flux:main>
    <div class="flex justify-between items-center">
        <div>
            <flux:heading size="xl">{{ $pageTitle }}</flux:heading>
        </div>
        <div>
            <flux:button href="{{ route('studio.catalog.bottle.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="Le Labo" wire:model.live.debounce.500ms="form.name"
                                            autofocus autocomplete="off" />
                                        <flux:error name="form.name" />
                                    </flux:field>

                                    <flux:field>
                                        <flux:label>Ukuran <span class="text-red-500 ms-1">*</span></flux:label>
                                        <flux:input placeholder="35" wire:model.live.debounce.500ms="form.size"
                                            autocomplete="off" />
                                        <flux:error name="form.size" />
                                    </flux:field>

                                    @if (auth()->user()->hasRole(['Developer', 'Owner']))
                                        <flux:field>
                                            <flux:label>Harga Beli <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="Masukkan harga beli"
                                                    x-mask:dynamic="$money($input, ',')"
                                                    wire:model.live.debounce.500ms="form.cost_price"
                                                    autocomplete="off" />
                                            </flux:input.group>
                                            <flux:error name="form.cost_price" />
                                        </flux:field>
                                    @endif

                                    <flux:field
                                        class="col-span-{{ auth()->user()->hasRole(['Developer', 'Owner'])? '1': '2' }}">
                                        <flux:label>Harga Jual <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="Masukkan harga jual"
                                                x-mask:dynamic="$money($input, ',')"
                                                wire:model.live.debounce.500ms="form.sale_price" autocomplete="off" />
                                        </flux:input.group>
                                        <flux:error name="form.sale_price" />
                                    </flux:field>

                                    <div class="md:col-span-2">
                                        <flux:editor label="Deskripsi" wire:model="form.description"
                                            placeholder="Botol Le Labo memiliki desain yang minimalis dan elegan, khas gaya modern klasik"
                                            auotocomplete="off" class="**:data-[slot=content]:min-h-[100px]!" />
                                    </div>
                                </div>
                            </flux:card>
                        </div>
                    </div>
                </div>

                <div class="w-full lg:w-1/3 space-y-4">
                    <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>

                    <flux:card class="space-y-6 p-6">
                        <div class="space-y-3">
                            <h3 class="text-sm font-medium">Gambar</h3>
                            <div class="dropzone-wrapper">
                                <livewire:dropzone wire:model="form.image" :rules="['image', 'mimes:png,jpeg', 'max:10420']" :max-files="1"
                                    :key="'image'" :files="$form->image" />
                                @error('form.image')
                                    <div role="alert" aria-live="polite" aria-atomic="true"
                                        class="mt-3 text-sm font-medium text-red-500 dark:text-red-400">
                                        <svg class="shrink-0 [:where(&amp;)]:size-5 inline" data-flux-icon=""
                                            xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor"
                                            aria-hidden="true" data-slot="icon">
                                            <path fill-rule="evenodd"
                                                d="M8.485 2.495c.673-1.167 2.357-1.167 3.03 0l6.28 10.875c.673 1.167-.17 2.625-1.516 2.625H3.72c-1.347 0-2.189-1.458-1.515-2.625L8.485 2.495ZM10 5a.75.75 0 0 1 .75.75v3.5a.75.75 0 0 1-1.5 0v-3.5A.75.75 0 0 1 10 5Zm0 9a1 1 0 1 0 0-2 1 1 0 0 0 0 2Z"
                                                clip-rule="evenodd"></path>
                                        </svg>
                                        {{ $message }}
                                    </div>
                                @enderror
                            </div>
                        </div>
                    </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>
