@props([
    'action',
    'method' => 'POST',
    'type' => null,
    'submitLabel',
])

<form method="POST" action="{{ $action }}" novalidate>
    @csrf
    @if (strtoupper($method) !== 'POST')
        @method($method)
    @endif

    <div class="card">
        <div class="card-body">
            <div class="row g-3">
                <div class="col-md-6">
                    <x-ui.form.input
                        name="name"
                        :label="__('leave.types.fields.name')"
                        :value="$type?->name"
                        required
                    />
                </div>
                <div class="col-md-3">
                    <x-ui.form.input
                        name="annual_limit"
                        type="number"
                        min="0"
                        :label="__('leave.types.fields.annual_limit')"
                        :value="old('annual_limit', $type?->annual_limit)"
                        optional
                    />
                </div>
                <div class="col-md-3">
                    <x-ui.form.select
                        name="is_paid"
                        :label="__('leave.types.fields.paid')"
                        :options="[1 => __('common.yes'), 0 => __('common.no')]"
                        :selected="old('is_paid', $type?->is_paid ?? true) ? 1 : 0"
                        required
                    />
                </div>
                <div class="col-md-3">
                    <x-ui.form.select
                        name="requires_approval"
                        :label="__('leave.types.fields.requires_approval')"
                        :options="[1 => __('common.yes'), 0 => __('common.no')]"
                        :selected="old('requires_approval', $type?->requires_approval ?? true) ? 1 : 0"
                        required
                    />
                </div>
                <div class="col-md-3">
                    <x-ui.form.select
                        name="allow_half_day"
                        :label="__('leave.types.fields.allow_half_day')"
                        :options="[1 => __('common.yes'), 0 => __('common.no')]"
                        :selected="old('allow_half_day', $type?->allow_half_day ?? false) ? 1 : 0"
                        required
                    />
                </div>
                <div class="col-md-3">
                    <x-ui.form.select
                        name="allow_negative_balance"
                        :label="__('leave.types.fields.allow_negative_balance')"
                        :options="[1 => __('common.yes'), 0 => __('common.no')]"
                        :selected="old('allow_negative_balance', $type?->allow_negative_balance ?? false) ? 1 : 0"
                        required
                    />
                </div>
                <div class="col-md-3">
                    <x-ui.form.select
                        name="requires_attachment"
                        :label="__('leave.types.fields.requires_attachment')"
                        :options="[1 => __('common.yes'), 0 => __('common.no')]"
                        :selected="old('requires_attachment', $type?->requires_attachment ?? false) ? 1 : 0"
                        required
                    />
                </div>
                @if ($type !== null)
                    <div class="col-md-3">
                        <x-ui.form.select
                            name="is_active"
                            :label="__('leave.fields.status')"
                            :options="[
                                1 => __('leave.types.status.active'),
                                0 => __('leave.types.status.inactive'),
                            ]"
                            :selected="$type->is_active ? 1 : 0"
                            required
                        />
                    </div>
                @endif
            </div>
        </div>
        <div class="card-footer d-flex justify-content-end gap-2 bg-white">
            <x-ui.buttons.secondary :href="route('hr.leave.types.index')">
                {{ __('common.cancel') }}
            </x-ui.buttons.secondary>
            <x-ui.buttons.primary type="submit">{{ $submitLabel }}</x-ui.buttons.primary>
        </div>
    </div>
</form>
