{{-- Item #8 — shared clinic-header + TPS-footer partial.

     Usage:
        @include('vetClinic::partials._print_branding', ['mode' => 'header'])
        @include('vetClinic::partials._print_branding', ['mode' => 'footer'])

     Reads $business from view scope when available, otherwise pulls the
     current session's business. Keeps every clinical printable in sync
     so a clinic-name change happens in one place. The footer renders
     "TPS - owner of the medical system" per the licensing requirement.
--}}
@php
    $__brand_business = $business ?? null;
    if (!$__brand_business) {
        try {
            $__brand_business = \App\Business::find(session('user.business_id'));
        } catch (\Throwable $e) {
            $__brand_business = null;
        }
    }
    $__brand_mode = $mode ?? 'header';
@endphp

@if($__brand_mode === 'header')
    <div class="vc-print-header" style="border-bottom:2pt solid #0f172a;padding-bottom:8pt;margin-bottom:12pt;">
        <table style="width:100%;border-collapse:collapse;">
            <tr>
                <td style="vertical-align:top;">
                    <div style="font-size:16pt;font-weight:bold;color:#0f172a;">
                        {{ optional($__brand_business)->name ?? config('app.name', 'Veterinary Clinic') }}
                    </div>
                    <div style="font-size:9pt;color:#64748b;line-height:1.4;margin-top:2pt;">
                        @if(optional($__brand_business)->mobile)<div>Phone: {{ $__brand_business->mobile }}</div>@endif
                        @if(optional($__brand_business)->email)<div>Email: {{ $__brand_business->email }}</div>@endif
                        @if(optional($__brand_business)->website)<div>Web: {{ $__brand_business->website }}</div>@endif
                        @if(optional($__brand_business)->tax_number_1)<div>Tax #: {{ $__brand_business->tax_number_1 }}</div>@endif
                    </div>
                </td>
                @isset($qrSrc)
                <td style="vertical-align:top;text-align:right;width:130pt;">
                    <img src="{{ $qrSrc }}" alt="QR"
                         style="width:95pt;height:95pt;border:0.5pt solid #cbd5e1;padding:3pt;background:#fff;">
                    <div style="font-size:7pt;color:#64748b;margin-top:3pt;">Scan to verify authenticity</div>
                </td>
                @endisset
            </tr>
        </table>
    </div>
@endif

@if($__brand_mode === 'footer')
    <div class="vc-print-footer" style="margin-top:14pt;padding-top:6pt;border-top:0.5pt solid #cbd5e1;font-size:7.5pt;color:#94a3b8;text-align:center;line-height:1.4;">
        @isset($verifyUrl)
            Scan the QR code to verify authenticity:
            <span style="color:#475569;word-break:break-all;">{{ $verifyUrl }}</span><br>
        @endisset
        <span style="color:#475569;font-weight:600;">
            Veterinary clinical record generated by
            {{ optional($__brand_business)->name ?? config('app.name') }}
        </span>
        <br>
        <span style="font-size:7pt;">
            Powered by <strong>TPS</strong> &mdash; owner of the medical system &copy; {{ now()->year }}.
            All rights reserved.
        </span>
    </div>
@endif
