@extends('layouts.app')

@section('title', 'Add Salary Component')
@section('heading', 'Add Salary Component')

@section('content')
    <x-card class="max-w-3xl">
        <form action="{{ route('salary-components.store') }}" method="POST" class="space-y-6" novalidate data-salary-component-form="create">
            @csrf
            <div class="grid gap-4 sm:grid-cols-2">
                <div>
                    <label class="block text-sm font-medium text-slate-700">Name <span class="text-red-500">*</span></label>
                    <input type="text" name="name" value="{{ old('name') }}" class="mt-1 block w-full rounded-lg border border-slate-300 px-3 py-2" placeholder="e.g. Basic Salary">
                    @error('name')<p class="mt-1 text-sm text-red-600">{{ $message }}</p>@enderror
                    <p data-js-error="name" class="mt-1 text-sm text-red-600 hidden"></p>
                </div>
                <div>
                    <label class="block text-sm font-medium text-slate-700">Type</label>
                    <select name="type" class="mt-1 block w-full rounded-lg border border-slate-300 px-3 py-2 js-select2" required>
                        <option value="earning" {{ old('type') === 'earning' ? 'selected' : '' }}>Earning</option>
                        <option value="deduction" {{ old('type') === 'deduction' ? 'selected' : '' }}>Deduction</option>
                    </select>
                </div>
                <div>
                    <label class="block text-sm font-medium text-slate-700">Value Type</label>
                    <select name="value_type" class="mt-1 block w-full rounded-lg border border-slate-300 px-3 py-2 js-select2">
                        <option value="fixed" {{ old('value_type') === 'fixed' ? 'selected' : '' }}>Fixed</option>
                        <option value="variable" {{ old('value_type') === 'variable' ? 'selected' : '' }}>Variable</option>
                        <option value="basic_percent" {{ old('value_type') === 'basic_percent' ? 'selected' : '' }}>Basic Percent</option>
                        <option value="ctc_percent" {{ old('value_type') === 'ctc_percent' ? 'selected' : '' }}>CTC Percent</option>
                        <option value="balancing_ctc" {{ old('value_type') === 'balancing_ctc' ? 'selected' : '' }}>Balancing Amount of CTC</option>
                        <option value="system_calculated" {{ old('value_type') === 'system_calculated' ? 'selected' : '' }}>System Calculated</option>
                    </select>
                </div>
                <div>
                    <label class="block text-sm font-medium text-slate-700">Default Amount</label>
                    <input type="number" name="default_amount" value="{{ old('default_amount', 0) }}" step="0.01" min="0" class="mt-1 block w-full rounded-lg border border-slate-300 px-3 py-2" required>
                    @error('default_amount')<p class="mt-1 text-sm text-red-600">{{ $message }}</p>@enderror
                </div>
                <div class="sm:col-span-2 flex items-center gap-2">
                    <input type="hidden" name="is_taxable" value="0">
                    <input type="checkbox" name="is_taxable" value="1" id="is_taxable" {{ old('is_taxable') ? 'checked' : '' }} class="rounded border-slate-300">
                    <label for="is_taxable" class="text-sm font-medium text-slate-700">Taxable</label>
                </div>
            </div>
            <div class="flex gap-2">
                <x-button type="submit" variant="primary">Save</x-button>
                <a href="{{ route('salary-components.index') }}" class="inline-flex items-center rounded-lg bg-slate-100 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-200">Cancel</a>
            </div>
        </form>
    </x-card>
@endsection

@push('scripts')
<script src="{{ asset('js/form-validation.js') }}"></script>
<script src="{{ asset('js/form-text-rules.js') }}"></script>
<script src="{{ asset('js/salary-component-form-validation.js') }}"></script>
@endpush
