@extends('layouts.user')

@section('title', __('salary.salary_setup'))
@section('page_title', __('salary.salary_setup'))
@section('breadcrumb', __('salary.hr_payroll'))

@section('content')
<div class="w-full px-1 sm:px-2 lg:px-3 space-y-5">

    <div class="mb-4 border border-slate-200 bg-white p-4 shadow-sm">
        <div class="mb-4">
            <h2 class="text-base font-bold text-slate-800">{{ __('salary.employee_salary_setup') }}</h2>
        </div>

        <form method="GET" class="flex flex-wrap items-center gap-2">
            <div>
                <input type="text"
                       name="search"
                       value="{{ request('search') }}"
                       placeholder="{{ __('salary.search_placeholder') }}"
                       class="w-56 border border-slate-200 px-3 py-2 text-xs outline-none focus:border-slate-400">
            </div>

            <div>
                <select name="employee_type" class="w-36 border border-slate-200 px-3 py-2 text-xs">
                    <option value="">{{ __('salary.all_types') }}</option>
                    <option value="monthly" @selected(request('employee_type') === 'monthly')>{{ __('salary.monthly') }}</option>
                    <option value="daily_roz" @selected(request('employee_type') === 'daily_roz')>{{ __('salary.daily_roz') }}</option>
                </select>
            </div>

            <div>
                <select name="status" class="w-36 border border-slate-200 px-3 py-2 text-xs">
                    <option value="">{{ __('salary.all_status') }}</option>
                    <option value="active" @selected(request('status') === 'active')>{{ __('salary.active') }}</option>
                    <option value="inactive" @selected(request('status') === 'inactive')>{{ __('salary.inactive') }}</option>
                </select>
            </div>

            <div class="flex gap-2">
                <button type="submit"
                        class="bg-blue-600 px-4 py-2 text-xs font-semibold text-white hover:bg-blue-700">
                    {{ __('salary.filter') }}
                </button>
                <a href="{{ route('user.hr.salary.index') }}"
                   class="border border-slate-200 px-4 py-2 text-xs font-semibold text-slate-700 hover:bg-slate-50">
                    {{ __('salary.reset') }}
                </a>
            </div>
        </form>
    </div>

    <div class="overflow-hidden border border-slate-200 bg-white shadow-sm">
        <div class="overflow-x-auto">
            <table class="min-w-full text-xs">
                <thead class="bg-slate-50">
                    <tr class="text-left text-slate-600">
                        <th class="px-4 py-3 font-semibold">{{ __('salary.employee') }}</th>
                        <th class="px-4 py-3 font-semibold">{{ __('salary.type') }}</th>
                        <th class="px-4 py-3 font-semibold">{{ __('salary.current_salary_rate') }}</th>
                        <th class="px-4 py-3 font-semibold">{{ __('salary.ot_rate') }}</th>
                        <th class="px-4 py-3 text-right font-semibold">{{ __('salary.action') }}</th>
                    </tr>
                </thead>

                <tbody class="divide-y divide-slate-100">
                    @forelse($employees as $employee)
                        <tr class="hover:bg-slate-50/70">
                            <td class="px-4 py-3">
                                <div>
                                    <div class="font-semibold text-slate-800">{{ $employee->name }}</div>
                                    <div class="text-[11px] text-slate-500">
                                        {{ $employee->employee_code }}
                                        @if($employee->designation)
                                            • {{ $employee->designation->name }}
                                        @endif
                                    </div>
                                </div>
                            </td>

                            <td class="px-4 py-3">
                                @if($employee->employee_type === 'monthly')
                                    <span class="border border-blue-200 bg-blue-50 px-2 py-1 text-[11px] font-semibold text-blue-700">
                                        {{ __('salary.monthly') }}
                                    </span>
                                @else
                                    <span class="border border-violet-200 bg-violet-50 px-2 py-1 text-[11px] font-semibold text-violet-700">
                                        {{ __('salary.daily_roz') }}
                                    </span>
                                @endif
                            </td>

                            <td class="px-4 py-3">
                                @if($employee->currentSalaryStructure)
                                    @if($employee->employee_type === 'monthly')
                                        <span class="font-semibold text-slate-800">
                                            ৳ {{ number_format($employee->currentSalaryStructure->monthly_salary, 2) }}/{{ __('salary.month') }}
                                        </span>
                                    @else
                                        <span class="font-semibold text-slate-800">
                                            ৳ {{ number_format($employee->currentSalaryStructure->per_roz_rate, 2) }}/{{ __('salary.roz') }}
                                        </span>
                                    @endif
                                @else
                                    <span class="font-semibold text-rose-600">{{ __('salary.not_set') }}</span>
                                @endif
                            </td>

                            <td class="px-4 py-3">
                                @if($employee->employee_type === 'monthly')
                                    @if($employee->currentSalaryStructure)
                                        ৳ {{ number_format($employee->currentSalaryStructure->overtime_rate, 2) }}
                                    @else
                                        -
                                    @endif
                                @else
                                    -
                                @endif
                            </td>

                            <td class="px-4 py-3">
                                <div class="flex items-center justify-end gap-2">
                                    @if($employee->currentSalaryStructure)
                                        <a href="{{ route('user.hr.salary.edit', $employee->id) }}"
                                           class="border border-amber-200 bg-amber-50 px-3 py-2 text-[11px] font-semibold text-amber-700 hover:bg-amber-100">
                                            {{ __('salary.change_rate') }}
                                        </a>
                                    @else
                                        <a href="{{ route('user.hr.salary.create', $employee->id) }}"
                                           class="border border-blue-200 bg-blue-50 px-3 py-2 text-[11px] font-semibold text-blue-700 hover:bg-blue-100">
                                            {{ __('salary.setup') }}
                                        </a>
                                    @endif

                                    <a href="{{ route('user.hr.salary.history', $employee->id) }}"
                                       class="border border-slate-200 px-3 py-2 text-[11px] font-semibold text-slate-700 hover:bg-slate-50">
                                        {{ __('salary.history') }}
                                    </a>
                                </div>
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="5" class="px-4 py-10 text-center text-xs text-slate-500">
                                {{ __('salary.no_employee_found') }}
                            </td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>

        @if($employees->hasPages())
            <div class="border-t border-slate-200 px-4 py-3">
                {{ $employees->links() }}
            </div>
        @endif
    </div>
</div>
@endsection