<?php
require_once 'includes/session.php';

// Format Member ID (e.g. BSES-2026-0001)
$member_number = str_pad($member['id'], 4, '0', STR_PAD_LEFT);
$member_id_str = "BSES-" . date('Y', strtotime($member['created_at'])) . "-" . $member_number;
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Membership ID Card - <?php echo h($member['name']); ?></title>
    <!-- Bootstrap 5 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- FontAwesome CSS -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <!-- Google Fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
    <style>
        body {
            background-color: #f1f5f9;
            font-family: 'Roboto', sans-serif;
            display: flex;
            flex-direction: column;
            align-items: center;
            padding: 40px 15px;
        }
        
        .id-card-container {
            width: 330px; /* Standard ID card size proportion (Vertical) */
            height: 520px;
            background: #fff;
            border-radius: 12px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.15);
            overflow: hidden;
            position: relative;
            margin-bottom: 30px;
            border: 2px solid #ddd;
        }

        /* Top Header of Card */
        .card-header-bg {
            background: linear-gradient(135deg, #A20E37 0%, #7a0827 100%);
            color: #fff;
            text-align: center;
            padding: 15px 10px 40px 10px;
            border-bottom-left-radius: 50% 20%;
            border-bottom-right-radius: 50% 20%;
            position: relative;
        }

        .card-logo {
            width: 60px;
            height: 60px;
            background: #fff;
            border-radius: 50%;
            padding: 5px;
            margin-bottom: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.2);
        }

        .trust-title {
            font-size: 0.85rem;
            font-weight: 700;
            line-height: 1.2;
            margin-bottom: 2px;
        }
        .trust-sub {
            font-size: 0.6rem;
            opacity: 0.9;
        }

        /* Photo Area */
        .member-photo-wrapper {
            text-align: center;
            margin-top: -45px; /* Overlap with header */
            position: relative;
            z-index: 2;
        }
        .member-photo {
            width: 110px;
            height: 110px;
            border-radius: 50%;
            object-fit: cover;
            border: 4px solid #fff;
            background: #eee;
            box-shadow: 0 4px 10px rgba(0,0,0,0.15);
        }

        /* Member Info */
        .member-info {
            text-align: center;
            padding: 15px 20px;
        }
        .member-name {
            font-size: 1.3rem;
            font-weight: 700;
            color: #1e293b;
            margin-bottom: 3px;
        }
        .member-desig {
            font-size: 0.9rem;
            font-weight: 500;
            color: #A20E37;
            text-transform: uppercase;
            margin-bottom: 15px;
            letter-spacing: 0.5px;
        }

        .detail-row {
            display: flex;
            align-items: center;
            margin-bottom: 6px;
            font-size: 0.8rem;
            text-align: left;
            border-bottom: 1px dashed #eee;
            padding-bottom: 4px;
        }
        .detail-label {
            font-weight: 700;
            color: #64748b;
            width: 65px;
        }
        .detail-value {
            color: #334155;
            font-weight: 500;
            flex: 1;
        }

        /* Bottom Footer of Card */
        .card-footer-strip {
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            background: #A20E37;
            color: #fff;
            text-align: center;
            padding: 8px;
            font-size: 0.7rem;
            font-weight: 500;
        }

        @media print {
            body { background: #fff; padding: 0; }
            .no-print { display: none !important; }
            .id-card-container { 
                box-shadow: none; 
                margin: 0; 
                -webkit-print-color-adjust: exact !important; 
                print-color-adjust: exact !important; 
            }
        }
    </style>
</head>
<body>

    <div class="mb-4 no-print text-center">
        <a href="index.php" class="btn btn-outline-secondary rounded-pill me-2"><i class="fas fa-arrow-left"></i> Back</a>
        <button onclick="window.print()" class="btn btn-primary rounded-pill fw-bold shadow"><i class="fas fa-print me-1"></i> Print ID Card</button>
        <div class="text-muted mt-2 small">For best results, set margins to "None" and enable "Background Graphics" in print settings.</div>
    </div>

    <!-- Front Side of ID Card -->
    <div class="id-card-container">
        
        <div class="card-header-bg">
            <img src="https://i.ibb.co/4gVbp8YZ/Whats-App-Image-2026-04-23-at-9-54-25-PM.png" alt="Logo" class="card-logo">
            <div class="trust-title">BHARTIYA SEVA EDUCATIONAL<br>SANGATHAN TRUST (BHARAT)</div>
            <div class="trust-sub">Registered under Government of India Trust Act</div>
        </div>

        <div class="member-photo-wrapper">
            <?php if(!empty($member['photo'])): ?>
                <img src="../assets/uploads/<?php echo $member['photo']; ?>" class="member-photo" alt="Photo">
            <?php else: ?>
                <div class="member-photo d-inline-flex align-items-center justify-content-center text-muted" style="font-size: 3rem;">
                    <i class="fas fa-user"></i>
                </div>
            <?php endif; ?>
        </div>

        <div class="member-info">
            <div class="member-name"><?php echo h($member['name']); ?></div>
            <div class="member-desig"><?php echo h($member['designation'] ?? 'MEMBER'); ?></div>
            
            <div class="detail-row">
                <div class="detail-label">ID No.</div>
                <div class="detail-value text-danger fw-bold"><?php echo $member_id_str; ?></div>
            </div>
            <div class="detail-row">
                <div class="detail-label">Phone</div>
                <div class="detail-value"><?php echo h($member['phone']); ?></div>
            </div>
            <div class="detail-row">
                <div class="detail-label">DOJ</div>
                <div class="detail-value"><?php echo date('d-M-Y', strtotime($member['created_at'])); ?></div>
            </div>
        </div>

        <div class="card-footer-strip">
            www.bhartiyasevatrust.in
        </div>

    </div>

</body>
</html>
