@extends('layouts.app')

@section('title', 'Form 16 — FY ' . $financial_year)
@section('heading', 'Form 16')

@section('content')
<div class="max-w-4xl space-y-6">
    <div class="flex flex-wrap items-center justify-between gap-4">
        <div>
            <h1 class="text-2xl font-bold text-slate-900">Form 16 (Part A summary)</h1>
            <p class="text-sm text-slate-600">Financial Year {{ $financial_year }} ({{ $period_from }} — {{ $period_to }})</p>
        </div>
        <a href="?download=1" class="rounded-lg bg-primary px-4 py-2 text-sm font-medium text-white">Download PDF</a>
    </div>

    <x-card>
        <dl class="grid gap-4 sm:grid-cols-2 text-sm">
            <div><dt class="text-slate-500">Employer</dt><dd class="font-medium">{{ $company->name ?? '—' }}</dd></div>
            <div><dt class="text-slate-500">Employee</dt><dd class="font-medium">{{ $user->name }}</dd></div>
            <div><dt class="text-slate-500">PAN</dt><dd class="font-medium">{{ $user->pan_number ?? '—' }}</dd></div>
            <div><dt class="text-slate-500">Tax regime</dt><dd class="font-medium uppercase">{{ $declaration->regime }}</dd></div>
            <div><dt class="text-slate-500">Gross salary (annual est.)</dt><dd class="font-medium">₹{{ number_format((float) $declaration->gross_annual_estimate, 2) }}</dd></div>
            <div><dt class="text-slate-500">Taxable income</dt><dd class="font-medium">₹{{ number_format((float) $declaration->taxable_income, 2) }}</dd></div>
            <div><dt class="text-slate-500">Tax on income</dt><dd class="font-medium">₹{{ number_format((float) $declaration->annual_tax, 2) }}</dd></div>
            <div><dt class="text-slate-500">Total TDS deducted</dt><dd class="font-medium">₹{{ number_format($total_tds_deducted, 2) }}</dd></div>
        </dl>
    </x-card>

    @if($declaration->items->isNotEmpty())
        <x-card>
            <h2 class="mb-3 text-sm font-semibold">Deductions verified</h2>
            <table class="min-w-full text-sm">
                <thead>
                    <tr class="border-b text-left text-slate-500">
                        <th class="pb-2">Section</th>
                        <th class="pb-2">Verified amount</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($declaration->items as $item)
                        <tr class="border-b border-slate-100">
                            <td class="py-2">{{ $item->section_name }}</td>
                            <td class="py-2">₹{{ number_format((float) ($item->verified_amount ?? $item->declared_amount), 2) }}</td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </x-card>
    @endif

    @if($tds_records->isNotEmpty())
        <x-card>
            <h2 class="mb-3 text-sm font-semibold">Monthly TDS deducted</h2>
            <table class="min-w-full text-sm">
                <thead>
                    <tr class="border-b text-left text-slate-500">
                        <th class="pb-2">Month</th>
                        <th class="pb-2">TDS</th>
                        <th class="pb-2">Cumulative</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($tds_records as $rec)
                        <tr class="border-b border-slate-100">
                            <td class="py-2">{{ date('M Y', mktime(0, 0, 0, $rec->month, 1, $rec->year)) }}</td>
                            <td class="py-2">₹{{ number_format((float) $rec->tds_amount, 2) }}</td>
                            <td class="py-2">₹{{ number_format((float) $rec->cumulative_tds, 2) }}</td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </x-card>
    @endif
</div>
@endsection
