<?php

/**
 * Guest Timeline Component Partial
 *
 * Renders a visual progress path mapping the guest's lifecycle journey.
 *
 * Variables:
 *   $guest          — array — The resolved guest record.
 *   $has_wish       — bool — Whether the guest has shared a wish.
 *   $checkin_record — array|null — Current checkin status if checked in.
 *
 * @package Inveetaire
 * @ref     RC-014
 */

$isInvitedSent = in_array(($guest['invitation_status'] ?? 'not_sent'), ['sent', 'opened']);
$isRsvpDone = in_array(($guest['rsvp_status'] ?? 'pending'), ['attending', 'declined']);
$isWishShared = (bool) ($has_wish ?? false);
$isCheckinDone = !empty($checkin_record);

?>

<div class="bg-white border border-slate-100 rounded-2xl p-6 shadow-sm">
    <h3 class="text-sm font-bold text-slate-800 tracking-tight mb-5">Guest Journey Timeline</h3>
    
    <div class="relative pl-6 border-l border-slate-100 space-y-6">
        
        <!-- Step 1: Invitation Delivery -->
        <div class="relative">
            <!-- Icon indicator circle -->
            <div class="absolute -left-[35px] top-0 w-5 h-5 rounded-full flex items-center justify-center text-[10px] font-bold <?= $isInvitedSent ? 'bg-purple-600 text-white' : 'bg-slate-100 text-slate-400' ?>">
                <?= $isInvitedSent ? '✓' : '1' ?>
            </div>
            <div>
                <h4 class="text-xs font-bold <?= $isInvitedSent ? 'text-slate-800' : 'text-slate-400' ?>">Invitation Delivery</h4>
                <p class="text-[11px] text-slate-500 mt-0.5">
                    <?php if (($guest['invitation_status'] ?? 'not_sent') === 'not_sent'): ?>
                        Pending queue distribution (Not Sent)
                    <?php else: ?>
                        Successfully distributed via WhatsApp (<?= escape_html(ucfirst($guest['invitation_status'])) ?>)
                    <?php endif; ?>
                </p>
            </div>
        </div>

        <!-- Step 2: RSVP Submission -->
        <div class="relative">
            <div class="absolute -left-[35px] top-0 w-5 h-5 rounded-full flex items-center justify-center text-[10px] font-bold <?= $isRsvpDone ? 'bg-purple-600 text-white' : 'bg-slate-100 text-slate-400' ?>">
                <?= $isRsvpDone ? '✓' : '2' ?>
            </div>
            <div>
                <h4 class="text-xs font-bold <?= $isRsvpDone ? 'text-slate-800' : 'text-slate-400' ?>">RSVP Confirmation</h4>
                <p class="text-[11px] text-slate-500 mt-0.5">
                    <?php if ($guest['rsvp_status'] === 'attending'): ?>
                        Confirmed Attending (<?= (int) $guest['invited_pax'] ?> Pax)
                    <?php elseif ($guest['rsvp_status'] === 'declined'): ?>
                        Declined invitation
                    <?php else: ?>
                        Pending guest response
                    <?php endif; ?>
                </p>
            </div>
        </div>

        <!-- Step 3: Warm Blessings -->
        <div class="relative">
            <div class="absolute -left-[35px] top-0 w-5 h-5 rounded-full flex items-center justify-center text-[10px] font-bold <?= $isWishShared ? 'bg-purple-600 text-white' : 'bg-slate-100 text-slate-400' ?>">
                <?= $isWishShared ? '✓' : '3' ?>
            </div>
            <div>
                <h4 class="text-xs font-bold <?= $isWishShared ? 'text-slate-800' : 'text-slate-400' ?>">Wishes & Blessings</h4>
                <p class="text-[11px] text-slate-500 mt-0.5">
                    <?php if ($isWishShared): ?>
                        Wish shared successfully
                    <?php else: ?>
                        No blessing text shared yet
                    <?php endif; ?>
                </p>
            </div>
        </div>

        <!-- Step 4: Check-In Scan -->
        <div class="relative">
            <div class="absolute -left-[35px] top-0 w-5 h-5 rounded-full flex items-center justify-center text-[10px] font-bold <?= $isCheckinDone ? 'bg-purple-600 text-white' : 'bg-slate-100 text-slate-400' ?>">
                <?= $isCheckinDone ? '✓' : '4' ?>
            </div>
            <div>
                <h4 class="text-xs font-bold <?= $isCheckinDone ? 'text-slate-800' : 'text-slate-400' ?>">Check-In Gate Scan</h4>
                <p class="text-[11px] text-slate-500 mt-0.5">
                    <?php if ($isCheckinDone): ?>
                        Checked-in at <?= date('d M Y, H:i', strtotime($checkin_record['checkin_time'])) ?> (Method: <?= escape_html(ucfirst($checkin_record['checkin_method'])) ?>)
                    <?php else: ?>
                        Awaiting check-in scan
                    <?php endif; ?>
                </p>
            </div>
        </div>

    </div>
</div>
