<?php
/**
 * Exit Permit Verification View
 * Save as: application/views/verify_exit_permit.php
 * 
 * This view displays the exit permit details when accessed via unique link
 */

// Helper function for date formatting (add to your helpers if not exists)
if (!function_exists('formatDate')) {
    function formatDate($date) {
        return date('d M, Y', strtotime($date));
    }
}
?>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <title>Exit Permit Verification</title>
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="<?=base_url()?>assets/css/style.css" />
    
    <style>
        body {
            font-family: 'Poppins', Arial, sans-serif;
            background-color: #f5f5f5;
            padding: 20px;
        }
        .verification-container {
            max-width: 800px;
            margin: 50px auto;
            background: white;
            border-radius: 10px;
            box-shadow: 0 0 20px rgba(0,0,0,0.1);
            overflow: hidden;
        }
        .header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 30px;
            text-align: center;
        }
        .header h1 {
            margin: 0;
            font-size: 28px;
            font-weight: 600;
        }
        .content {
            padding: 40px;
        }
        .applicant-photo {
            width: 150px;
            height: 150px;
            border-radius: 10px;
            object-fit: cover;
            border: 3px solid #667eea;
            box-shadow: 0 4px 10px rgba(0,0,0,0.1);
        }
        .info-row {
            margin: 20px 0;
            padding: 15px;
            background: #f8f9fa;
            border-radius: 8px;
            border-left: 4px solid #667eea;
        }
        .info-label {
            font-weight: 600;
            color: #555;
            font-size: 14px;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            margin-bottom: 5px;
        }
        .info-value {
            font-size: 18px;
            color: #333;
            font-weight: 500;
        }
        .verification-badge {
            display: inline-block;
            background: #28a745;
            color: white;
            padding: 8px 20px;
            border-radius: 20px;
            font-weight: 600;
            margin-top: 10px;
        }
        .error-message {
            text-align: center;
            padding: 60px 20px;
        }
        .error-message h2 {
            color: #dc3545;
            margin-bottom: 20px;
        }
        .footer {
            background: #f8f9fa;
            padding: 20px;
            text-align: center;
            border-top: 1px solid #ddd;
            color: #666;
            font-size: 14px;
        }
        @media (max-width: 768px) {
            .applicant-photo {
                width: 120px;
                height: 120px;
                margin: 0 auto 20px;
                display: block;
            }
            .content {
                padding: 20px;
            }
        }
    </style>
</head>
<body>

<div class="verification-container">
    <?php if(isset($error) && $error != ''): ?>
        <!-- Error State -->
        <div class="header">
            <h1>⚠️ Verification Failed</h1>
        </div>
        <div class="error-message">
            <h2>Invalid Verification Key</h2>
            <p><?= $error ?></p>
            <p>Please check the URL and try again.</p>
        </div>
    <?php else: ?>
        <?php foreach($clients as $client): ?>
        <!-- Success State -->
        <div class="header">
            <h1>✓ Exit Permit Verified</h1>
            <div class="verification-badge">Authentic Document</div>
        </div>
        
        <div class="content">
            <div class="row">
                <!-- Photo Column -->
                <div class="col-md-4 text-center">
                    <?php if($client['image1']): ?>
                        <img src="<?=base_url('assets/avator/upload/')?><?=$client['image1']?>" 
                             class="applicant-photo" 
                             alt="<?=$client['name']?>">
                    <?php else: ?>
                        <div class="applicant-photo" style="background: #ddd; display: flex; align-items: center; justify-content: center;">
                            <span style="font-size: 50px; color: #999;">👤</span>
                        </div>
                    <?php endif; ?>
                </div>
                
                <!-- Details Column -->
                <div class="col-md-8">
                    <div class="info-row">
                        <div class="info-label">Full Name</div>
                        <div class="info-value"><?=$client['name']?></div>
                    </div>
                    
                    <div class="info-row">
                        <div class="info-label">Passport Number</div>
                        <div class="info-value"><?=$client['pass_no']?></div>
                    </div>
                    
                    <div class="info-row">
                        <div class="info-label">Country</div>
                        <div class="info-value"><?=$client['country']?></div>
                    </div>
                </div>
            </div>
            
            <!-- Additional Details -->
            <hr style="margin: 30px 0;">
            
            <div class="row">
                <div class="col-md-6">
                    <div class="info-row">
                        <div class="info-label">Start Date</div>
                        <div class="info-value"><?=formatDate($client['start_date'])?></div>
                    </div>
                </div>
                
                <div class="col-md-6">
                    <div class="info-row">
                        <div class="info-label">End Date</div>
                        <div class="info-value"><?=formatDate($client['end_date'])?></div>
                    </div>
                </div>
            </div>
            
            <?php if($client['ref_no']): ?>
            <div class="info-row">
                <div class="info-label">Reference Number</div>
                <div class="info-value"><?=$client['ref_no']?></div>
            </div>
            <?php endif; ?>
            
            <div class="info-row">
                <div class="info-label">Verification Code</div>
                <div class="info-value" style="font-family: monospace; color: #667eea;">
                    <?=$client['random_key']?>
                </div>
            </div>
            
            <?php if(isset($client['created_date']) && $client['created_date']): ?>
            <div style="text-align: center; margin-top: 30px; color: #999; font-size: 13px;">
                <i>Document issued on: <?=formatDate($client['created_date'])?></i>
            </div>
            <?php endif; ?>
        </div>
        <?php endforeach; ?>
    <?php endif; ?>
    
    <div class="footer">
        <p style="margin: 0;">
            <strong>Exit Permit Verification System</strong><br>
            © <?=date('Y')?> - All Rights Reserved
        </p>
        <p style="margin: 10px 0 0 0; font-size: 12px;">
            This is an official verification document. Do not share this link publicly.
        </p>
    </div>
</div>

<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>

</body>
</html>