{{-- Standard optical spectacle-prescription print layout. Receives $patient
     (ClcPatient), $rx (OpthGlassesRx), $business (App\Business). --}}
@php
    use Modules\OphthalmologyClinic\Entities\OpthGlassesRx;
    $name = $patient->patient_name ?: optional($patient->contact)->name;
@endphp
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>{{ __('ophthClinic::lang.spectacle_rx') }} — {{ $name }}</title>
    <style>
        * { box-sizing: border-box; }
        body { font-family: "Segoe UI", Arial, sans-serif; color: #1e293b; margin: 0; padding: 24px; }
        .rx-sheet { max-width: 720px; margin: 0 auto; border: 1px solid #cbd5e1; border-radius: 8px; padding: 24px; }
        .rx-header { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid #6610f2; padding-bottom: 12px; margin-bottom: 16px; }
        .clinic-name { font-size: 20px; font-weight: 700; color: #6610f2; }
        .clinic-meta { font-size: 12px; color: #64748b; margin-top: 4px; }
        .rx-title { text-align: right; }
        .rx-title h1 { font-size: 16px; margin: 0; letter-spacing: 1px; text-transform: uppercase; }
        .rx-symbol { font-size: 34px; font-weight: 700; color: #6610f2; line-height: 1; }
        .meta-row { display: flex; gap: 24px; font-size: 13px; margin-bottom: 16px; }
        .meta-row div span { color: #64748b; }
        table.rx { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
        table.rx th, table.rx td { border: 1px solid #cbd5e1; padding: 8px 10px; text-align: center; font-size: 14px; }
        table.rx th { background: #f1f5f9; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
        table.rx td.eye { font-weight: 700; background: #faf5ff; text-align: left; }
        .rx-foot { display: flex; justify-content: space-between; font-size: 13px; margin-top: 24px; }
        .sig { border-top: 1px solid #94a3b8; padding-top: 4px; width: 220px; text-align: center; color: #64748b; }
        .notes { font-size: 12px; color: #475569; margin-top: 8px; }
        @media print { body { padding: 0; } .rx-sheet { border: none; } .noprint { display: none; } }
    </style>
</head>
<body onload="window.print()">
    <div class="rx-sheet">
        <div class="rx-header">
            <div>
                <div class="clinic-name">{{ $business->name ?? 'Clinic' }}</div>
                <div class="clinic-meta">
                    @if(!empty($business->mobile)) {{ $business->mobile }} &nbsp; @endif
                    @if(!empty($business->email)) {{ $business->email }} &nbsp; @endif
                    @if(!empty($business->city)) {{ $business->city }} @endif
                </div>
            </div>
            <div class="rx-title">
                <div class="rx-symbol">&#8478;</div>
                <h1>{{ __('ophthClinic::lang.spectacle_rx') }}</h1>
            </div>
        </div>

        <div class="meta-row">
            <div><span>{{ __('ophthClinic::lang.patient') }}:</span> <strong>{{ $name }}</strong></div>
            <div><span>{{ __('ophthClinic::lang.date') }}:</span> {{ optional($rx->prescribed_at)->format('Y-m-d') ?: now()->format('Y-m-d') }}</div>
            @if($rx->pd_mm !== null)<div><span>{{ __('ophthClinic::lang.pd') }}:</span> {{ rtrim(rtrim(number_format($rx->pd_mm,1),'0'),'.') }}</div>@endif
        </div>

        <table class="rx">
            <thead>
                <tr>
                    <th></th>
                    <th>Sphere (SPH)</th>
                    <th>Cylinder (CYL)</th>
                    <th>Axis</th>
                    <th>Add</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td class="eye">{{ __('ophthClinic::lang.right_eye_od') }}</td>
                    <td>{{ OpthGlassesRx::dpt($rx->sphere_od) }}</td>
                    <td>{{ OpthGlassesRx::dpt($rx->cylinder_od) }}</td>
                    <td>{{ $rx->axis_od !== null ? $rx->axis_od : '—' }}</td>
                    <td>{{ $rx->add_od !== null ? OpthGlassesRx::dpt($rx->add_od) : '—' }}</td>
                </tr>
                <tr>
                    <td class="eye">{{ __('ophthClinic::lang.left_eye_os') }}</td>
                    <td>{{ OpthGlassesRx::dpt($rx->sphere_os) }}</td>
                    <td>{{ OpthGlassesRx::dpt($rx->cylinder_os) }}</td>
                    <td>{{ $rx->axis_os !== null ? $rx->axis_os : '—' }}</td>
                    <td>{{ $rx->add_os !== null ? OpthGlassesRx::dpt($rx->add_os) : '—' }}</td>
                </tr>
            </tbody>
        </table>

        @if($rx->lens_type)
            <div class="notes"><strong>{{ __('ophthClinic::lang.lens_type') }}:</strong> {{ OpthGlassesRx::LENS_TYPES[$rx->lens_type] ?? $rx->lens_type }}</div>
        @endif
        @if($rx->notes)
            <div class="notes"><strong>{{ __('ophthClinic::lang.notes') }}:</strong> {{ $rx->notes }}</div>
        @endif

        <div class="rx-foot">
            <div></div>
            <div class="sig">{{ __('ophthClinic::lang.signature') }}</div>
        </div>
    </div>
</body>
</html>
