@extends('layouts.app')

@section('title', 'Invoices — TechCorp Manager')

@section('content')
<div data-tc-api-page="invoices">
    <div class="tc-page-head-row">
        <div class="tc-page-head">
            <h2>Invoices</h2>
            <p>Billing and payment status. Create and edit invoices via the API.</p>
        </div>
        <button type="button" class="tc-btn-primary" id="tc-add-invoice">+ New invoice</button>
    </div>

    <div class="tc-card">
        <div class="tc-table-wrap">
            <table class="tc-table">
                <thead>
                    <tr>
                        <th>Invoice #</th>
                        <th>Client</th>
                        <th>Date</th>
                        <th>Due</th>
                        <th>Total</th>
                        <th>Status</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    @forelse ($invoices as $invoice)
                        <tr>
                            <td><strong>{{ $invoice->invoice_number }}</strong></td>
                            <td>{{ $invoice->client?->name ?? '—' }}</td>
                            <td>{{ $invoice->date?->format('M j, Y') }}</td>
                            <td>{{ $invoice->due_date?->format('M j, Y') ?? '—' }}</td>
                            <td>${{ number_format((float) $invoice->total, 2) }}</td>
                            <td><span class="tc-badge {{ $invoice->status }}">{{ $invoice->status }}</span></td>
                            <td class="tc-table-actions">
                                <a href="{{ route('web.invoices.document', $invoice) }}" class="tc-btn-sm" target="_blank" rel="noopener">Print</a>
                                <a href="{{ route('web.invoices.pdf', $invoice) }}" class="tc-btn-sm">PDF</a>
                                <button type="button" class="tc-btn-sm tc-edit-invoice" data-id="{{ $invoice->id }}">Edit</button>
                                <button type="button" class="tc-btn-sm danger tc-del-invoice" data-id="{{ $invoice->id }}">Delete</button>
                            </td>
                        </tr>
                    @empty
                        <tr><td colspan="7" class="tc-empty">No invoices yet.</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>
</div>
@endsection
