@php
    $embedded = $embedded ?? false;
    $documentCopyLabel = $documentCopyLabel ?? ($documentCopies['original'] ?? 'Original Copy');
    $closeUrl = $closeUrl ?? route('admin.payments.index', request()->except('payment'));
@endphp

<div class="billing-invoice-preview {{ $embedded ? 'billing-invoice-preview--embedded' : '' }}">
    <div class="billing-invoice-preview__toolbar no-print">
        <div class="billing-invoice-preview__toolbar-left">
            @if(! $embedded)
                <a href="{{ route('admin.payments.index') }}" class="btn btn-light btn-sm border" title="Back to list">
                    <i class="ri-arrow-left-line"></i>
                </a>
            @endif
        </div>
        <div class="billing-invoice-preview__actions">
            <a href="{{ route('admin.payments.edit', $payment) }}" class="btn btn-panel-action btn-sm">
                <i class="ri-pencil-line"></i><span>Edit</span>
            </a>
            <a href="{{ route('admin.payments.pdf', $payment) }}" class="btn btn-panel-action btn-sm" title="Download PDF">
                <i class="ri-file-pdf-line"></i><span>PDF</span>
            </a>
            <a href="{{ route('admin.payments.print', ['payment' => $payment, 'copy' => 'original', 'autoprint' => 1]) }}"
               target="_blank" rel="noopener" class="btn btn-panel-action btn-sm" title="Print">
                <i class="ri-printer-line"></i><span>Print</span>
            </a>
            <button type="button" class="btn btn-panel-action btn-sm" id="payment-get-link-btn"
                data-share-url="{{ route('admin.payments.share-link', $payment) }}" title="Share link">
                <i class="ri-link"></i><span>Get Link</span>
            </button>
            <div class="dropdown">
                <button type="button" class="btn btn-panel-action btn-sm dropdown-toggle" data-bs-toggle="dropdown">
                    <i class="ri-more-2-line"></i><span>More</span>
                </button>
                <ul class="dropdown-menu dropdown-menu-end">
                    <li>
                        <form action="{{ route('admin.payments.destroy', $payment) }}" method="POST" onsubmit="return confirm('Delete this payment?')">
                            @csrf @method('DELETE')
                            <button type="submit" class="dropdown-item text-danger">
                                <i class="ri-delete-bin-line me-2"></i>Delete
                            </button>
                        </form>
                    </li>
                </ul>
            </div>
            <a href="{{ $closeUrl }}" class="btn btn-light btn-sm border-0" title="Close">
                <i class="ri-close-line fs-18"></i>
            </a>
        </div>
    </div>

    <div class="billing-invoice-preview__body row g-0">
        <div class="col-lg-3 billing-invoice-preview__sidebar no-print">
            <div class="billing-invoice-preview__sidebar-inner">
                <span class="billing-invoice-preview__badge"><i class="ri-eye-line"></i> Live preview</span>
                <div class="billing-invoice-preview__panel">
                    <p class="billing-invoice-preview__panel-title">Document copy</p>
                    <select class="form-select form-select-sm" id="document-copy-select">
                        @foreach($documentCopies as $key => $label)
                            <option value="{{ $key }}" @selected($key === 'original')>{{ $label }}</option>
                        @endforeach
                    </select>
                </div>
                <div class="d-grid gap-2">
                    <a href="{{ route('admin.preferences.payments') }}" class="btn btn-light btn-sm border text-start">
                        <i class="ri-settings-3-line me-2"></i> Payment settings
                    </a>
                </div>
            </div>
        </div>
        <div class="col-lg-9 billing-invoice-preview__main">
            <div class="billing-invoice-preview__canvas-wrap">
                <div class="billing-invoice-preview__canvas p-3 p-lg-4" id="payment-preview-canvas">
                    @include('admin.payments.partials._document', [
                        'documentCopyLabel' => $documentCopyLabel,
                        'logoSrc' => $logoSrc ?? null,
                        'signatureSrc' => $signatureSrc ?? null,
                    ])
                </div>
            </div>
        </div>
    </div>
</div>

@include('admin.payments.partials.share-link-modal')
