<?php $__env->startSection('title', $patient->full_name); ?>
<?php $__env->startSection('heading'); ?>
    <div style="display:flex; align-items:center; gap:0.75rem;">
        <span><?php echo e($patient->full_name); ?></span>
        <span class="pill pill-muted" style="font-size: 0.9rem;"><?php echo e($patient->patient_code); ?></span>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
    <!-- Action Bar -->
    <div class="flex-between mb-1" style="display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 1rem;">
        <div class="flex gap" style="flex-wrap: wrap;">
            <a href="<?php echo e(route('visits.create', ['patient_id' => $patient->id])); ?>" class="btn btn-primary btn-sm">➕ <?php echo e(__('clinic.new_visit')); ?></a>
            <a href="<?php echo e(route('invoices.create', ['patient_id' => $patient->id])); ?>" class="btn btn-ghost btn-sm">💵 <?php echo e(__('clinic.new_invoice')); ?></a>
            <a href="<?php echo e(route('patients.print-card', $patient)); ?>" target="_blank" class="btn btn-ghost btn-sm">🪪 <?php echo e(__('clinic.print_card')); ?></a>
            <a href="<?php echo e(route('patients.print-file', $patient)); ?>" target="_blank" class="btn btn-ghost btn-sm">📄 <?php echo e(__('clinic.print_file')); ?></a>
        </div>
        <div class="flex gap">
            <a href="<?php echo e(route('patients.edit', $patient)); ?>" class="btn btn-ghost btn-sm">⚙ <?php echo e(__('clinic.edit_patient')); ?></a>
            <form method="POST" action="<?php echo e(route('patients.destroy', $patient)); ?>" onsubmit="return confirm('<?php echo e(__('Are you sure you want to delete this patient?')); ?>')" style="margin:0;">
                <?php echo csrf_field(); ?>
                <?php echo method_field('DELETE'); ?>
                <button type="submit" class="btn btn-ghost btn-sm" style="color:var(--danger)">🗑 <?php echo e(__('clinic.delete_patient')); ?></button>
            </form>
        </div>
    </div>

    <!-- Layout Grid -->
    <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1.5rem; margin-top: 1rem; align-items: start;">
        <!-- Left Side: Patient Info & QR Card -->
        <div style="display: flex; flex-direction: column; gap: 1.5rem;">
            <!-- QR Card -->
            <div class="card" style="text-align: center; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; padding: 2rem 1.5rem;">
                <h4 style="margin:0; font-size:1.1rem; color:var(--primary);"><?php echo e(__('clinic.clinic_card')); ?></h4>
                <div style="background: #fff; padding: 10px; border-radius: var(--radius-sm); box-shadow: 0 4px 12px rgba(0,0,0,0.05); display: inline-block;">
                    <?php echo $qrCode; ?>

                </div>
                <div>
                    <strong style="font-size: 1rem; color: var(--text);"><?php echo e($patient->patient_code); ?></strong>
                    <div style="font-size: 0.85rem; color: var(--muted); margin-top: 0.25rem;">
                        <?php echo e(__('clinic.registration_date')); ?>: <?php echo e($patient->created_at->format('Y-m-d')); ?>

                    </div>
                </div>
            </div>

            <!-- Profile Info Details -->
            <div class="card">
                <h3 class="card-title" style="margin-top:0; border-bottom:1px solid var(--border); padding-bottom:0.5rem; margin-bottom:1rem; font-size:1rem;">ℹ️ <?php echo e(__('clinic.overview')); ?></h3>
                <dl class="detail-grid" style="display: grid; grid-template-columns: 1fr; gap: 0.85rem; margin:0;">
                    <div>
                        <dt style="font-size: 0.85rem; color: var(--muted); font-weight: 500;"><?php echo e(__('clinic.phone')); ?></dt>
                        <dd style="margin:0; font-weight:600; font-size:0.95rem; color:var(--text);"><a href="tel:<?php echo e($patient->phone); ?>"><?php echo e($patient->phone); ?></a></dd>
                    </div>
                    <?php if($patient->whatsapp): ?>
                    <div>
                        <dt style="font-size: 0.85rem; color: var(--muted); font-weight: 500;"><?php echo e(__('clinic.whatsapp')); ?></dt>
                        <dd style="margin:0; font-weight:600; font-size:0.95rem; color:var(--text);"><a href="https://wa.me/<?php echo e(preg_replace('/\D/', '', $patient->whatsapp)); ?>" target="_blank"><?php echo e($patient->whatsapp); ?></a></dd>
                    </div>
                    <?php endif; ?>
                    <div>
                        <dt style="font-size: 0.85rem; color: var(--muted); font-weight: 500;"><?php echo e(__('clinic.gender')); ?></dt>
                        <dd style="margin:0; font-weight: 600;"><?php echo e(__('clinic.' . $patient->gender)); ?></dd>
                    </div>
                    <?php if($patient->age || $patient->birth_date): ?>
                    <div>
                        <dt style="font-size: 0.85rem; color: var(--muted); font-weight: 500;"><?php echo e(__('clinic.age')); ?> / <?php echo e(__('clinic.birth_date')); ?></dt>
                        <dd style="margin:0; font-weight: 600;">
                            <?php if($patient->age): ?> <?php echo e($patient->age); ?> <?php echo e(__('سنوات')); ?> <?php endif; ?>
                            <?php if($patient->birth_date): ?> (<?php echo e($patient->birth_date->format('Y-m-d')); ?>) <?php endif; ?>
                        </dd>
                    </div>
                    <?php endif; ?>
                    <?php if($patient->national_id): ?>
                    <div>
                        <dt style="font-size: 0.85rem; color: var(--muted); font-weight: 500;"><?php echo e(__('clinic.national_id')); ?></dt>
                        <dd style="margin:0; font-weight: 600;"><?php echo e($patient->national_id); ?></dd>
                    </div>
                    <?php endif; ?>
                    <?php if($patient->address): ?>
                    <div>
                        <dt style="font-size: 0.85rem; color: var(--muted); font-weight: 500;"><?php echo e(__('clinic.address')); ?></dt>
                        <dd style="margin:0; font-weight: 600; line-height: 1.4;"><?php echo e($patient->address); ?></dd>
                    </div>
                    <?php endif; ?>
                </dl>
            </div>

            <!-- Emergency Info -->
            <?php if($patient->emergency_contact_name || $patient->emergency_contact_phone): ?>
            <div class="card">
                <h3 class="card-title" style="margin-top:0; border-bottom:1px solid var(--border); padding-bottom:0.5rem; margin-bottom:1rem; font-size:1rem; color:var(--accent-rose)">🚨 <?php echo e(__('clinic.emergency_contact_name')); ?></h3>
                <dl class="detail-grid" style="display: grid; grid-template-columns: 1fr; gap: 0.85rem; margin:0;">
                    <?php if($patient->emergency_contact_name): ?>
                    <div>
                        <dt style="font-size: 0.85rem; color: var(--muted);"><?php echo e(__('clinic.emergency_contact_name')); ?></dt>
                        <dd style="margin:0; font-weight:600;"><?php echo e($patient->emergency_contact_name); ?></dd>
                    </div>
                    <?php endif; ?>
                    <?php if($patient->emergency_contact_phone): ?>
                    <div>
                        <dt style="font-size: 0.85rem; color: var(--muted);"><?php echo e(__('clinic.emergency_contact_phone')); ?></dt>
                        <dd style="margin:0; font-weight:600;"><a href="tel:<?php echo e($patient->emergency_contact_phone); ?>"><?php echo e($patient->emergency_contact_phone); ?></a></dd>
                    </div>
                    <?php endif; ?>
                </dl>
            </div>
            <?php endif; ?>
        </div>

        <!-- Right Side: Medical Background, Visit timeline, and Invoices -->
        <div style="display: flex; flex-direction: column; gap: 1.5rem; grid-column: span 2;">
            <!-- Medical Background Header -->
            <div class="card">
                <h3 class="card-title" style="margin-top: 0; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; margin-bottom: 1.25rem; font-size: 1.1rem; color: var(--accent-emerald);">
                    📋 <?php echo e(__('clinic.medical_history')); ?>

                </h3>
                <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 1rem;">
                    <div style="border-left: 2px solid var(--border); padding-left: 0.75rem; border-right: 2px solid var(--border); padding-right: 0.75rem;">
                        <h4 style="margin: 0 0 0.5rem 0; font-size: 0.9rem; color: var(--muted);"><?php echo e(__('clinic.chronic_diseases')); ?></h4>
                        <p style="margin: 0; font-weight: 600; font-size:0.95rem;"><?php echo nl2br(e($patient->chronic_diseases ?? '—')); ?></p>
                    </div>
                    <div>
                        <h4 style="margin: 0 0 0.5rem 0; font-size: 0.9rem; color: var(--muted);"><?php echo e(__('clinic.allergies')); ?></h4>
                        <p style="margin: 0; font-weight: 600; font-size:0.95rem;"><?php echo nl2br(e($patient->allergies ?? '—')); ?></p>
                    </div>
                </div>
                <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1.25rem; border-top: 1px dashed var(--border); padding-top: 1rem;">
                    <div style="border-left: 2px solid var(--border); padding-left: 0.75rem; border-right: 2px solid var(--border); padding-right: 0.75rem;">
                        <h4 style="margin: 0 0 0.5rem 0; font-size: 0.9rem; color: var(--muted);"><?php echo e(__('clinic.current_medications')); ?></h4>
                        <p style="margin: 0; font-weight: 600; font-size:0.95rem;"><?php echo nl2br(e($patient->current_medications ?? '—')); ?></p>
                    </div>
                    <div>
                        <h4 style="margin: 0 0 0.5rem 0; font-size: 0.9rem; color: var(--muted);"><?php echo e(__('clinic.medical_history')); ?></h4>
                        <p style="margin: 0; font-weight: 600; font-size:0.95rem;"><?php echo nl2br(e($patient->medical_history ?? '—')); ?></p>
                    </div>
                </div>
                <?php if($patient->notes): ?>
                <div style="margin-top: 1rem; border-top: 1px dashed var(--border); padding-top: 1rem;">
                    <h4 style="margin: 0 0 0.5rem 0; font-size: 0.9rem; color: var(--muted);"><?php echo e(__('clinic.notes')); ?></h4>
                    <p style="margin: 0; font-size: 0.9rem;"><?php echo e($patient->notes); ?></p>
                </div>
                <?php endif; ?>
            </div>

            <!-- Visits Timeline -->
            <div class="card">
                <div class="card-title-row" style="display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; margin-bottom: 1.25rem;">
                    <h3 class="card-title" style="margin:0; font-size: 1.1rem; color: var(--primary);">
                        🩺 <?php echo e(__('clinic.visits')); ?>

                    </h3>
                    <span class="pill pill-muted"><?php echo e(count($patient->visits)); ?></span>
                </div>

                <div style="display: flex; flex-direction: column; gap: 1.25rem;">
                    <?php $__empty_1 = true; $__currentLoopData = $patient->visits; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $v): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <div class="visit-item" style="border-right: 3px solid var(--primary); padding-right: 1.25rem; position: relative;">
                            <div style="display: flex; justify-content: space-between; align-items: start; flex-wrap: wrap;">
                                <div>
                                    <h4 style="margin:0; font-size:1rem;"><a href="<?php echo e(route('visits.show', $v)); ?>"><?php echo e($v->chief_complaint); ?></a></h4>
                                    <span style="font-size:0.8rem; color:var(--muted)">
                                        📅 <?php echo e($v->visit_date->format('Y-m-d H:i')); ?> · 👨‍⚕️ <?php echo e($v->doctor->name ?? '—'); ?>

                                    </span>
                                </div>
                                <span class="pill <?php if($v->status === 'completed'): ?> pill-success <?php elseif($v->status === 'waiting'): ?> pill-muted <?php else: ?> pill-danger <?php endif; ?>">
                                    <?php echo e(__('clinic.' . $v->status)); ?>

                                </span>
                            </div>
                            
                            <?php if($v->diagnosis): ?>
                            <div style="margin-top: 0.5rem; font-size: 0.9rem;">
                                <strong><?php echo e(__('clinic.diagnosis')); ?>:</strong> <?php echo e($v->diagnosis); ?>

                            </div>
                            <?php endif; ?>

                            <?php if($v->prescription_notes): ?>
                            <div style="margin-top: 0.25rem; font-size: 0.9rem; color: var(--text-secondary); background: var(--bg); padding: 0.5rem; border-radius: var(--radius-sm); margin-top: 0.5rem;">
                                <strong>💊 <?php echo e(__('clinic.prescription_notes')); ?>:</strong> <?php echo e($v->prescription_notes); ?>

                            </div>
                            <?php endif; ?>
                            <div style="margin-top: 0.5rem;">
                                <a href="<?php echo e(route('visits.show', $v)); ?>" class="btn btn-ghost btn-sm" style="padding: 2px 8px; font-size:0.8rem;"><?php echo e(__('clinic.view_all')); ?> →</a>
                            </div>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <p style="margin:0; color:var(--muted); text-align:center; padding: 1rem 0;"><?php echo e(__('clinic.no_records')); ?></p>
                    <?php endif; ?>
                </div>
            </div>

            <!-- Invoices -->
            <div class="card">
                <div class="card-title-row" style="display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; margin-bottom: 1.25rem;">
                    <h3 class="card-title" style="margin:0; font-size: 1.1rem; color: var(--accent-cyan);">
                        💵 <?php echo e(__('clinic.invoices')); ?>

                    </h3>
                </div>

                <div class="table-wrap" style="margin:0;">
                    <table class="data-table" style="width: 100%;">
                        <thead>
                            <tr>
                                <th><?php echo e(__('clinic.invoice_number')); ?></th>
                                <th><?php echo e(__('clinic.total_amount')); ?></th>
                                <th><?php echo e(__('clinic.paid_amount')); ?></th>
                                <th><?php echo e(__('clinic.remaining_amount')); ?></th>
                                <th><?php echo e(__('clinic.payment_status')); ?></th>
                                <th></th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $__empty_1 = true; $__currentLoopData = $patient->invoices; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $inv): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                <tr>
                                    <td><strong><a href="<?php echo e(route('invoices.show', $inv)); ?>"><?php echo e($inv->invoice_number); ?></a></strong></td>
                                    <td><?php echo e(number_format($inv->total_amount, 2)); ?></td>
                                    <td><?php echo e(number_format($inv->paid_amount, 2)); ?></td>
                                    <td style="color: <?php echo e($inv->remaining_amount > 0 ? 'var(--danger)' : 'inherit'); ?>"><?php echo e(number_format($inv->remaining_amount, 2)); ?></td>
                                    <td>
                                        <span class="pill <?php if($inv->payment_status === 'paid'): ?> pill-success <?php elseif($inv->payment_status === 'partial'): ?> pill-warning <?php else: ?> pill-danger <?php endif; ?>">
                                            <?php echo e(__('clinic.' . $inv->payment_status)); ?>

                                        </span>
                                    </td>
                                    <td>
                                        <a href="<?php echo e(route('invoices.show', $inv)); ?>" class="btn btn-ghost btn-sm">Open</a>
                                    </td>
                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                <tr>
                                    <td colspan="6" style="text-align:center; color:var(--muted)"><?php echo e(__('clinic.no_records')); ?></td>
                                </tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\clinic-system\resources\views/patients/show.blade.php ENDPATH**/ ?>