<?php
// myaccount.php — Imperial Premium Bank (Bootstrap 5 Edition)

// Load user data
$dataFile = __DIR__ . '/data.json';
if (!file_exists($dataFile)) {
    die("data.json not found. Please create it first.");
}
$data = json_decode(file_get_contents($dataFile), true);

// Current account info
$account = $data['account'] ?? [];
$user_ip = $_SERVER['REMOTE_ADDR'] ?? 'Unknown';
$message = '';

// Handle POST to update profile
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $account['owner'] = trim($_POST['owner']);
    $account['email'] = trim($_POST['email']);
    $account['phone'] = trim($_POST['phone']);
    $account['address'] = trim($_POST['address']);
    $account['last_updated'] = date('c');

    $data['account'] = $account;
    file_put_contents($dataFile, json_encode($data, JSON_PRETTY_PRINT));
    $message = 'Profile updated successfully.';
}
?>

<!doctype html>

<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>My Account – Imperial Premium Bank</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
  <style>
    :root {
      --ipb-blue: #0d6efd;
      --ipb-red: #dc3545;
      --ipb-bg: #f8f9fb;
    }
    body {
      background: var(--ipb-bg);
      font-family: "Inter", system-ui, sans-serif;
    }
    .sidebar {
      background: #fff;
      min-height: 100vh;
      box-shadow: 0 0 10px rgba(0,0,0,0.05);
      padding-top: 20px;
    }
    .sidebar a {
      display: block;
      padding: 12px 20px;
      color: #333;
      text-decoration: none;
      border-left: 3px solid transparent;
    }
    .sidebar a.active, .sidebar a:hover {
      background: rgba(13,110,253,0.05);
      border-left-color: var(--ipb-blue);
      color: var(--ipb-blue);
    }
    .topbar {
      background: #fff;
      padding: 15px 25px;
      box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    }
    .profile-pic {
      width: 70px;
      height: 70px;
      border-radius: 50%;
      object-fit: cover;
    }
  </style>
</head>
<body>
<div class="container-fluid">
  <div class="row">
    <!-- Sidebar -->
    <nav class="col-md-3 col-lg-2 sidebar">
      <div class="text-center mb-4">
        <img src="logo.png" alt="Imperial Premium Bank" style="max-width:140px;">
      </div>
      <a href="dashboard.php">Dashboard</a>
      <a href="myaccount.php" class="active">My Account</a>
      <a href="account_summary.php">Account Summary</a>
      <a href="transfer.php">Transfer</a>
      <a href="business_loan.php">Business Loan</a>
      <a href="support.php">Support</a>
      <a href="logout.php" class="text-danger mt-4 d-block">Logout</a>
    </nav>

```
<!-- Main content -->
<main class="col-md-9 col-lg-10">
  <div class="topbar d-flex justify-content-between align-items-center">
    <h5 class="m-0 fw-semibold text-primary">My Account</h5>
    <span class="text-muted small">Logged in from IP: <?php echo htmlspecialchars($user_ip); ?></span>
  </div>

  <div class="container mt-4">
    <?php if ($message): ?>
      <div class="alert alert-success"><?php echo htmlspecialchars($message); ?></div>
    <?php endif; ?>

    <div class="card shadow-sm border-0">
      <div class="card-body">
        <div class="d-flex align-items-center mb-4">
          <img src="<?php echo htmlspecialchars($account['profile_pic'] ?? 'profile.png'); ?>" class="profile-pic me-3" alt="Profile">
          <div>
            <h5 class="mb-1"><?php echo htmlspecialchars($account['owner'] ?? 'User'); ?></h5>
            <small class="text-muted">Account Type: <?php echo htmlspecialchars($account['type'] ?? 'Personal Checking'); ?></small><br>
            <small class="text-muted">Account #: <?php echo htmlspecialchars($account['account_number'] ?? '---- ---- ---- ----'); ?></small>
          </div>
        </div>

        <form method="post" class="row g-3">
          <div class="col-md-6">
            <label class="form-label">Full Name</label>
            <input type="text" name="owner" value="<?php echo htmlspecialchars($account['owner'] ?? ''); ?>" class="form-control" required>
          </div>
          <div class="col-md-6">
            <label class="form-label">Email</label>
            <input type="email" name="email" value="<?php echo htmlspecialchars($account['email'] ?? ''); ?>" class="form-control" required>
          </div>
          <div class="col-md-6">
            <label class="form-label">Phone</label>
            <input type="text" name="phone" value="<?php echo htmlspecialchars($account['phone'] ?? ''); ?>" class="form-control">
          </div>
          <div class="col-md-6">
            <label class="form-label">Address</label>
            <input type="text" name="address" value="<?php echo htmlspecialchars($account['address'] ?? ''); ?>" class="form-control">
          </div>
          <div class="col-md-6">
            <label class="form-label">Last Login</label>
            <input type="text" class="form-control" readonly value="<?php echo htmlspecialchars($account['last_login'] ?? date('Y-m-d H:i')); ?>">
          </div>
          <div class="col-md-6">
            <label class="form-label">Current IP</label>
            <input type="text" class="form-control" readonly value="<?php echo htmlspecialchars($user_ip); ?>">
          </div>
          <div class="col-12 mt-3">
            <button type="submit" class="btn btn-primary px-4">Save Changes</button>
            <button type="reset" class="btn btn-outline-secondary px-4">Reset</button>
          </div>
        </form>
      </div>
    </div>

  </div>
</main>
```

  </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>

</body>
</html>
