@extends('layouts.app')

@section('title', 'Deduction sections')
@section('heading', 'Deduction sections')

@section('content')
    <div class="mb-6 flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
        <p class="text-slate-600">Manage deduction sections (e.g. 80C, 80D) for income tax. <a href="{{ route('superadmin.income-tax-plans.index') }}" class="font-medium text-primary hover:underline">Income tax plans</a></p>
        <a href="{{ route('superadmin.deduction-sections.create') }}" class="inline-flex rounded-lg bg-primary px-4 py-2 text-sm font-medium text-white"><i class="bi bi-plus-lg me-1"></i>Add section</a>
    </div>

    <x-card>
        <div class="overflow-x-auto">
            <x-table>
                <x-slot name="head">
                    <tr>
                        <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500">Section code</th>
                        <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500">Section name</th>
                        <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500">Limit amount</th>
                        <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500">Status</th>
                        <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500">Actions</th>
                    </tr>
                </x-slot>
                @forelse($sections as $section)
                    <tr class="hover:bg-slate-50">
                        <td class="whitespace-nowrap px-4 py-3 font-medium text-slate-900">{{ $section->section_code }}</td>
                        <td class="whitespace-nowrap px-4 py-3 text-sm text-slate-600">{{ $section->section_name }}</td>
                        <td class="whitespace-nowrap px-4 py-3 text-sm text-slate-600">{{ $section->limit_amount !== null ? number_format($section->limit_amount, 2) : '—' }}</td>
                        <td class="whitespace-nowrap px-4 py-3">
                            <x-badge :status="$section->is_active ? 'active' : 'inactive'">{{ $section->is_active ? 'Active' : 'Inactive' }}</x-badge>
                        </td>
                        <td class="whitespace-nowrap px-4 py-3">
                            <a href="{{ route('superadmin.deduction-sections.edit', $section) }}" class="btn-icon-action btn-icon-action--edit" title="Edit" aria-label="Edit"><i class="bi bi-pencil-square"></i></a>
                            <form action="{{ route('superadmin.deduction-sections.destroy', $section) }}" method="post" class="inline ml-2" onsubmit="return confirm('Delete this section?');">
                                @csrf
                                @method('DELETE')
                                <button type="submit" class="btn-icon-action btn-icon-action--delete" title="Delete" aria-label="Delete"><i class="bi bi-trash3"></i></button>
                            </form>
                        </td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="5" class="px-4 py-8 text-center text-sm text-slate-500">No deduction sections. <a href="{{ route('superadmin.deduction-sections.create') }}" class="text-primary underline">Add one</a>.</td>
                    </tr>
                @endforelse
            </x-table>
        </div>
    </x-card>
@endsection
