<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}" dir="{{ html_dir() }}">
<head>
<meta charset="utf-8"><title>{{ $invoice->invoice_number }}</title>
<style>
@font-face { font-family: Amiri; src: url("{{ asset('fonts/Amiri-Regular.ttf') }}") format("truetype"); font-weight: 400; }
@font-face { font-family: Amiri; src: url("{{ asset('fonts/Amiri-Bold.ttf') }}") format("truetype"); font-weight: 700; }
body { padding: 24px; font-family: Amiri, Tahoma, Arial, sans-serif; color: #111; }
h1 { font-size: 22px; margin: 0 0 6px; }
h2 { font-size: 16px; margin: 12px 0; }
table { width: 100%; border-collapse: collapse; margin-top: 12px; }
th, td { border: 1px solid #ccc; padding: 8px; text-align: {{ html_dir() === 'rtl' ? 'right' : 'left' }}; }
th { background: #f3f3f3; }
.toolbar { margin-bottom: 16px; display: flex; flex-wrap: wrap; gap: 8px; }
.toolbar a, .toolbar button { padding: 8px 12px; border: 1px solid #999; background: #fff; text-decoration: none; color: #111; cursor: pointer; }
.alert { padding: 8px 12px; background: #d1e7dd; margin-bottom: 12px; }
@media print { .no-print { display: none; } }
</style>
</head>
<body>
@php
    $hideName = $hideName ?? request()->boolean('hide_name');
    $paidMonths = $invoice->items->map(fn ($item) => $item->billingPeriod?->label())->filter()->unique()->values();
@endphp
<div class="toolbar no-print">
    <button type="button" onclick="window.print()">{{ __('messages.print') }}</button>
    <a href="{{ route('invoices.pdf', $invoice) }}{{ $hideName ? '?hide_name=1' : '' }}">PDF</a>
    @if($hideName)
        <a href="{{ route('invoices.print', $invoice) }}">{{ __('messages.show_customer_name') }}</a>
    @else
        <a href="{{ route('invoices.print', [$invoice, 'hide_name' => 1]) }}">{{ __('messages.hide_customer_name') }}</a>
    @endif
    @if($invoice->line)
        <a href="{{ route('billing.show', $invoice->line) }}">{{ __('nav.billing') }}</a>
    @endif
</div>
@if(session('success'))<div class="alert no-print">{{ session('success') }}</div>@endif
@if(company_logo_url())
<img src="{{ company_logo_url() }}" alt="{{ setting('company_name') }}" style="max-height:64px;max-width:180px">
@endif
<h1>{{ setting('company_name') }}</h1>
<p>{{ setting('company_address') }} · {{ setting('company_phone') }}</p>
<h2>{{ $invoice->invoice_number }} — {{ $invoice->date?->toDateString() }}</h2>
<p>{{ __('messages.line') }}: <strong>{{ $invoice->line?->phone_number }}</strong></p>
@if(! $hideName && $invoice->customer?->name)
<p>{{ __('messages.customer') }}: {{ $invoice->customer->name }}</p>
@endif
@if($paidMonths->isNotEmpty())
<p>{{ __('messages.paid_months') }}: <strong>{{ $paidMonths->join('، ') }}</strong></p>
@endif
<table>
<thead><tr><th>{{ __('messages.items') }}</th><th>{{ __('messages.price') }}</th><th>{{ __('messages.total') }}</th></tr></thead>
<tbody>@foreach($invoice->items as $item)<tr><td>{{ $item->billingPeriod?->label() ?: $item->description }}</td><td>{{ money($item->unit_price) }}</td><td>{{ money($item->total) }}</td></tr>@endforeach</tbody>
<tfoot><tr><th>{{ __('messages.total') }}</th><th></th><th>{{ money($invoice->total) }}</th></tr></tfoot>
</table>
<p>{{ setting('invoice_footer') }}</p>
</body>
</html>
