@php
    $field = 'h-9 w-full rounded-md border border-line bg-inset px-3 font-sans text-sm text-ink placeholder:text-ink-4 focus:border-accent/40 focus:outline-none';
    $label = 'mb-1 block font-mono text-[11px] uppercase tracking-wider text-ink-3';
    $err = 'mt-1 flex items-center gap-1.5 font-mono text-[11px] text-offline';
@endphp

<div class="space-y-5">
    <x-panel :title="__('mail.title')" :subtitle="__('mail.subtitle')">
        <form wire:submit="save" class="space-y-4">
            <div class="grid gap-4 sm:grid-cols-[minmax(0,1fr)_120px]">
                <div>
                    <label class="{{ $label }}">{{ __('mail.host') }}</label>
                    <input wire:model="mail_host" type="text" class="{{ $field }} font-mono" placeholder="smtp.example.com" />
                    @error('mail_host') <p class="{{ $err }}"><x-icon name="alert" class="h-3.5 w-3.5 shrink-0" />{{ $message }}</p> @enderror
                </div>
                <div>
                    <label class="{{ $label }}">{{ __('mail.port') }}</label>
                    <input wire:model="mail_port" type="text" inputmode="numeric" class="{{ $field }} font-mono" />
                    @error('mail_port') <p class="{{ $err }}"><x-icon name="alert" class="h-3.5 w-3.5 shrink-0" />{{ $message }}</p> @enderror
                </div>
            </div>

            <div class="grid gap-4 sm:grid-cols-2">
                <div>
                    <label class="{{ $label }}">{{ __('mail.username') }}</label>
                    <input wire:model="mail_username" type="text" autocomplete="off" class="{{ $field }} font-mono" />
                    @error('mail_username') <p class="{{ $err }}"><x-icon name="alert" class="h-3.5 w-3.5 shrink-0" />{{ $message }}</p> @enderror
                </div>
                <div>
                    <label class="{{ $label }}">{{ __('mail.password') }}</label>
                    <input wire:model="mail_password" type="password" autocomplete="new-password"
                           placeholder="{{ $passwordSet ? __('mail.password_set_placeholder') : '' }}"
                           class="{{ $field }} font-mono" />
                    @error('mail_password') <p class="{{ $err }}"><x-icon name="alert" class="h-3.5 w-3.5 shrink-0" />{{ $message }}</p> @enderror
                </div>
            </div>

            <div class="grid gap-4 sm:grid-cols-2">
                <div>
                    <label class="{{ $label }}">{{ __('mail.encryption') }}</label>
                    <select wire:model="mail_encryption" class="{{ $field }} font-mono">
                        <option value="none">{{ __('mail.encryption_none') }}</option>
                        <option value="tls">{{ __('mail.encryption_tls') }}</option>
                        <option value="ssl">{{ __('mail.encryption_ssl') }}</option>
                    </select>
                    @error('mail_encryption') <p class="{{ $err }}"><x-icon name="alert" class="h-3.5 w-3.5 shrink-0" />{{ $message }}</p> @enderror
                </div>
            </div>

            <div class="grid gap-4 sm:grid-cols-2">
                <div>
                    <label class="{{ $label }}">{{ __('mail.from_address') }}</label>
                    <input wire:model="mail_from_address" type="text" class="{{ $field }} font-mono" placeholder="panel@example.com" />
                    @error('mail_from_address') <p class="{{ $err }}"><x-icon name="alert" class="h-3.5 w-3.5 shrink-0" />{{ $message }}</p> @enderror
                </div>
                <div>
                    <label class="{{ $label }}">{{ __('mail.from_name') }}</label>
                    <input wire:model="mail_from_name" type="text" class="{{ $field }}" placeholder="Clusev" />
                    @error('mail_from_name') <p class="{{ $err }}"><x-icon name="alert" class="h-3.5 w-3.5 shrink-0" />{{ $message }}</p> @enderror
                </div>
            </div>

            <div class="flex flex-wrap justify-end gap-2 border-t border-line pt-4">
                <x-btn variant="secondary" type="button" wire:click="sendTest" wire:target="sendTest" wire:loading.attr="disabled"
                       :disabled="! $this->configured()">
                    <svg wire:loading wire:target="sendTest" class="h-3.5 w-3.5 animate-spin" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" aria-hidden="true"><path d="M21 12a9 9 0 1 1-6.219-8.56" stroke-linecap="round" /></svg>
                    {{ __('mail.test_send') }}
                </x-btn>
                <x-btn variant="primary" type="submit" wire:target="save" wire:loading.attr="disabled">
                    <svg wire:loading wire:target="save" class="h-3.5 w-3.5 animate-spin" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" aria-hidden="true"><path d="M21 12a9 9 0 1 1-6.219-8.56" stroke-linecap="round" /></svg>
                    {{ __('common.save') }}
                </x-btn>
            </div>
        </form>
    </x-panel>
</div>
