@extends('layouts.public-document')
@section('title', 'Invoice ' . $invoice->invoice_number)

@section('content')
@php
    $documentCopyLabel = $documentCopyLabel ?? ($documentCopies['original'] ?? 'Original Copy');
    $invoiceTitle = $invoiceTitle ?? \App\Helpers\InvoiceDocumentSettings::titleForType($invoice->type, $company->id ?? null);
@endphp

<div class="billing-public-invoice">
    <header class="billing-public-invoice__topbar">
        <div class="billing-public-invoice__brand">
            @if($logoSrc ?? null)
                <img src="{{ $logoSrc }}" alt="" class="billing-public-invoice__logo">
            @endif
            <span class="billing-public-invoice__company">{{ $company->name }}</span>
        </div>
        <div class="billing-public-invoice__topbar-actions">
            @if($company->phone || $company->email)
                <span class="billing-public-invoice__contact-pill">
                    Contact {{ $company->name }}
                </span>
            @endif
            <span class="billing-public-invoice__client-pill">
                Client name: <strong>{{ $invoice->customer->name }}</strong>
            </span>
        </div>
    </header>

    <div class="billing-public-invoice__toolbar">
        <div class="billing-public-invoice__toolbar-left">
            <a href="{{ route('public.invoices.pdf', ['token' => $shareToken]) }}" class="btn billing-public-invoice__btn-export">
                Export PDF
            </a>
            <a href="{{ route('public.invoices.print', ['token' => $shareToken, 'autoprint' => 1]) }}"
               target="_blank"
               rel="noopener"
               class="btn billing-public-invoice__btn-print">
                Print
            </a>
        </div>
        <div class="billing-public-invoice__summary">
            <div><span class="label">Invoice #</span> <strong>{{ $invoice->invoice_number }}</strong></div>
            <div><span class="label">Due Date</span> <strong>{{ $invoice->due_date?->format('d - M - Y') ?? '—' }}</strong></div>
            <div><span class="label">Amount Due</span> <strong class="amount">₹ {{ number_format($invoice->balance, 2) }}</strong></div>
        </div>
    </div>

    <main class="billing-public-invoice__document">
        <div class="billing-public-invoice__canvas">
            @include('admin.invoices.partials._document', [
                'invoiceTitle' => $invoiceTitle,
                'documentCopyLabel' => $documentCopyLabel,
                'layout' => 'a4',
                'forPublic' => true,
                'logoSrc' => $logoSrc,
                'signatureSrc' => $signatureSrc,
            ])
        </div>
    </main>
</div>
@endsection

@push('styles')
<link href="{{ asset('css/billing-invoice-document.css') }}" rel="stylesheet">
<link href="{{ asset('css/billing-invoice-print.css') }}" rel="stylesheet">
<link href="{{ asset('css/billing-public-invoice.css') }}" rel="stylesheet">
@endpush
