<?php
$page_title = 'My Profile';
require_once __DIR__ . '/header.php';

// Handle mock edit profile
$success = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_profile'])) {
    $success = 'Profile updated successfully.';
}
?>

<?php if ($success): ?>
<div style="background:#dcfce7;color:#16a34a;padding:12px;border-radius:8px;margin-bottom:20px;border:1px solid #bbf7d0;">
  <i class="fas fa-check-circle"></i> <?= h($success) ?>
</div>
<?php endif; ?>

<div class="grid-3">
  <!-- Digital ID & Basic Info -->
  <div class="card" style="grid-column: span 1;text-align:center;">
    <div style="width:120px;height:120px;border-radius:50%;margin:0 auto 16px;border:4px solid #f8fafc;box-shadow:0 4px 10px rgba(0,0,0,0.1);overflow:hidden;">
        <img src="<?= SITE_URL ?>/assets/images/logo.jpg" alt="Profile" style="width:100%;height:100%;object-fit:cover;">
    </div>
    <h3 style="margin:0 0 4px;color:#0f172a;font-size:1.4rem;"><?= h($emp['name']) ?></h3>
    <p style="margin:0 0 8px;color:#2557d6;font-weight:600;font-size:1rem;"><?= h($emp['designation'] ?? $dept) ?></p>
    <div style="background:#f1f5f9;padding:6px 12px;border-radius:12px;font-family:monospace;font-size:1.1rem;font-weight:700;display:inline-block;color:#475569;margin-bottom:20px;">
        <?= h($_SESSION['emp_code']) ?>
    </div>
    <hr style="border:0;border-top:1px solid #e2e8f0;margin:0 0 20px;">
    
    <button onclick="document.getElementById('editProfileModal').style.display='block'" class="btn-primary" style="width:100%;padding:10px;background:#fff;color:#0f172a;border:1px solid #cbd5e1;border-radius:6px;cursor:pointer;font-weight:600;"><i class="fas fa-edit"></i> Edit Profile</button>
  </div>

  <!-- Detailed Info -->
  <div class="card" style="grid-column: span 2;">
    <!-- Tabs Navigation (Visual only) -->
    <div style="border-bottom:1px solid #e2e8f0;margin-bottom:20px;display:flex;gap:20px;">
      <span style="padding-bottom:12px;border-bottom:2px solid #2557d6;color:#2557d6;font-weight:600;cursor:pointer;">Personal Info</span>
      <span style="padding-bottom:12px;color:#64748b;font-weight:500;cursor:pointer;">Job Info</span>
      <span style="padding-bottom:12px;color:#64748b;font-weight:500;cursor:pointer;">Bank Info</span>
      <span style="padding-bottom:12px;color:#64748b;font-weight:500;cursor:pointer;">Documents</span>
    </div>

    <div class="grid-2">
      <div>
        <label style="display:block;font-size:0.8rem;color:#64748b;margin-bottom:4px;">Full Name</label>
        <p style="margin:0 0 16px;color:#0f172a;font-weight:500;"><?= h($emp['name']) ?></p>
      </div>
      <div>
        <label style="display:block;font-size:0.8rem;color:#64748b;margin-bottom:4px;">Father's Name</label>
        <p style="margin:0 0 16px;color:#0f172a;font-weight:500;">Suresh Kumar</p>
      </div>
      <div>
        <label style="display:block;font-size:0.8rem;color:#64748b;margin-bottom:4px;">Date of Birth</label>
        <p style="margin:0 0 16px;color:#0f172a;font-weight:500;">12 Aug 1990</p>
      </div>
      <div>
        <label style="display:block;font-size:0.8rem;color:#64748b;margin-bottom:4px;">Gender</label>
        <p style="margin:0 0 16px;color:#0f172a;font-weight:500;">Male</p>
      </div>
      <div>
        <label style="display:block;font-size:0.8rem;color:#64748b;margin-bottom:4px;">Mobile Number</label>
        <p style="margin:0 0 16px;color:#0f172a;font-weight:500;"><?= h($emp['phone'] ?: '9876543210') ?></p>
      </div>
      <div>
        <label style="display:block;font-size:0.8rem;color:#64748b;margin-bottom:4px;">Email Address</label>
        <p style="margin:0 0 16px;color:#0f172a;font-weight:500;"><?= h($emp['email']) ?></p>
      </div>
      <div style="grid-column: span 2;">
        <label style="display:block;font-size:0.8rem;color:#64748b;margin-bottom:4px;">Current Address</label>
        <p style="margin:0 0 16px;color:#0f172a;font-weight:500;line-height:1.5;">123, Industrial Area, Morbi,<br>Gujarat - 363641</p>
      </div>
      <div>
        <label style="display:block;font-size:0.8rem;color:#64748b;margin-bottom:4px;">Aadhaar Number</label>
        <p style="margin:0 0 16px;color:#0f172a;font-weight:500;">XXXX-XXXX-1234</p>
      </div>
      <div>
        <label style="display:block;font-size:0.8rem;color:#64748b;margin-bottom:4px;">PAN Number</label>
        <p style="margin:0 0 16px;color:#0f172a;font-weight:500;">ABCDE1234F</p>
      </div>
      <div>
        <label style="display:block;font-size:0.8rem;color:#64748b;margin-bottom:4px;">Emergency Contact</label>
        <p style="margin:0 0 16px;color:#0f172a;font-weight:500;">9988776655 (Wife)</p>
      </div>
    </div>
  </div>
</div>

<!-- Edit Profile Modal -->
<div id="editProfileModal" style="display:none;position:fixed;inset:0;background:rgba(15,23,42,0.6);z-index:999;align-items:center;justify-content:center;">
  <div style="background:#fff;width:100%;max-width:500px;border-radius:12px;padding:24px;position:relative;margin:10vh auto;box-shadow:0 20px 25px -5px rgba(0,0,0,0.1);">
    <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:20px;">
      <h3 style="margin:0;">Edit Profile</h3>
      <button type="button" onclick="document.getElementById('editProfileModal').style.display='none'" style="background:none;border:none;font-size:1.2rem;cursor:pointer;color:#64748b;"><i class="fas fa-times"></i></button>
    </div>
    <form method="POST">
      <div style="margin-bottom:16px;">
        <label style="display:block;font-size:0.85rem;font-weight:600;margin-bottom:6px;">Mobile Number</label>
        <input type="text" name="phone" value="<?= h($emp['phone'] ?: '9876543210') ?>" style="width:100%;padding:10px;border:1px solid #cbd5e1;border-radius:6px;">
      </div>
      <div style="margin-bottom:16px;">
        <label style="display:block;font-size:0.85rem;font-weight:600;margin-bottom:6px;">Current Address</label>
        <textarea name="address" style="width:100%;padding:10px;border:1px solid #cbd5e1;border-radius:6px;height:80px;resize:none;">123, Industrial Area, Morbi, Gujarat - 363641</textarea>
      </div>
      <div style="margin-bottom:24px;">
        <label style="display:block;font-size:0.85rem;font-weight:600;margin-bottom:6px;">Emergency Contact</label>
        <input type="text" name="emergency" value="9988776655 (Wife)" style="width:100%;padding:10px;border:1px solid #cbd5e1;border-radius:6px;">
      </div>
      <div style="display:flex;justify-content:flex-end;gap:12px;">
        <button type="button" onclick="document.getElementById('editProfileModal').style.display='none'" style="padding:10px 16px;background:#f1f5f9;color:#475569;border:none;border-radius:6px;cursor:pointer;font-weight:600;">Cancel</button>
        <button type="submit" name="update_profile" style="padding:10px 16px;background:#2557d6;color:#fff;border:none;border-radius:6px;cursor:pointer;font-weight:600;">Save Changes</button>
      </div>
    </form>
  </div>
</div>
<script>
// Show modal automatically if flex layout is missing in inline styles
document.getElementById('editProfileModal').style.display = 'none';
</script>

<?php require_once __DIR__ . '/footer.php'; ?>
