<x-ui.modal>
    <div class="flex items-center justify-between">
        <h3 class="text-base font-semibold text-ink">{{ __('finance.series_edit_title') }}</h3>
        <span class="rounded bg-surface-2 px-2 py-0.5 font-mono text-xs text-muted">{{ $prefix }}</span>
    </div>

    <div class="mt-4 space-y-4">
        <x-ui.input name="name" wire:model="name" :label="__('finance.series.name')" />

        {{-- Editable only while nothing has been issued. The prefix is part of
             every number already on a document: changing it renames nothing and
             leaves a series whose past says RE and whose future says AR. --}}
        <div>
            <label class="text-sm font-medium text-body" for="series-prefix">{{ __('finance.series.prefix') }}</label>
            @if ($issued === 0)
                <input id="series-prefix" type="text" wire:model="prefix"
                       class="mt-1.5 w-full rounded-md border border-line-strong bg-surface px-3 py-2 font-mono text-sm uppercase text-ink" />
            @else
                <input id="series-prefix" type="text" value="{{ $prefix }}" disabled
                       class="mt-1.5 w-full cursor-not-allowed rounded-md border border-line bg-surface-2 px-3 py-2 font-mono text-sm text-muted" />
                <p class="mt-1 text-xs text-muted">{{ __('finance.series_locked', ['n' => $issued]) }}</p>
            @endif
            @error('prefix')<p class="mt-1 text-xs text-danger">{{ $message }}</p>@enderror
        </div>

        <div class="grid gap-4 sm:grid-cols-2">
            <x-ui.input name="digits" wire:model="digits" type="number" :label="__('finance.series.digits')" />
            <div>
                <label class="text-sm font-medium text-body" for="series-next">{{ __('finance.series.next') }}</label>
                <input id="series-next" type="number" min="{{ $floor }}" wire:model="nextNumber"
                       class="mt-1.5 w-full rounded-md border border-line-strong bg-surface px-3 py-2 font-mono text-sm text-ink" />
                <p class="mt-1 text-xs text-muted">{{ __('finance.series_floor', ['n' => $floor]) }}</p>
                @error('nextNumber')<p class="mt-1 text-xs text-danger">{{ $message }}</p>@enderror
            </div>
        </div>

        @if ($issued === 0)
            <div class="rounded-lg border border-line bg-surface-2 p-4">
                <x-ui.checkbox name="yearlyReset" wire:model="yearlyReset" :label="__('finance.series.reset_label')" />
                <p class="mt-1.5 pl-7 text-xs text-muted">{{ __('finance.series.reset_hint') }}</p>
            </div>
        @endif

        <div class="rounded-lg border border-line bg-surface-2 p-4">
            <x-ui.checkbox name="active" wire:model="active" :label="__('finance.series.active_label')" />
            <p class="mt-1.5 pl-7 text-xs text-muted">{{ __('finance.series.active_hint') }}</p>
        </div>
    </div>

    <x-slot:footer>
        <div class="flex justify-end gap-3">
            <x-ui.button variant="secondary" x-on:click="Livewire.dispatch('closeModal')">{{ __('finance.cancel') }}</x-ui.button>
            <x-ui.button variant="primary" wire:click="save" wire:loading.attr="disabled">{{ __('finance.save') }}</x-ui.button>
        </div>
    </x-slot:footer>
</x-ui.modal>
