<?php
/**
 * Account Notifications Page
 * Converted from account-notifications.html
 * User notification preferences
 */

$pageTitle = 'Cartzilla | Cont - Notificări';
$pageDescription = 'Cartzilla - Magazin Online E-Commerce';

require_once __DIR__ . '/includes/header.php';

// Initialize classes
$auth = new Auth();
$db = Database::getInstance();

// Check if user is logged in
if (!$auth->isLoggedIn()) {
    header('Location: /cont/login?redirect=' . urlencode($_SERVER['REQUEST_URI']));
    exit;
}

$userId = $auth->getUserId();
$userData = $auth->getUser();

$message = '';
$error = '';

// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'update_notifications') {
    // For now, we'll just show a success message
    // In the future, this can be stored in a user_preferences table
    $message = 'Preferințele de notificări au fost actualizate cu succes!';
}
?>

<!-- Page content -->
<main class="content-wrapper">
  <div class="container py-5 mt-n2 mt-sm-0">
    <div class="row pt-md-2 pt-lg-3 pb-sm-2 pb-md-3 pb-lg-4 pb-xl-5">

      <!-- Sidebar navigation -->
      <aside class="col-lg-3">
        <div class="offcanvas-lg offcanvas-start pe-lg-0 pe-xl-4" id="accountSidebar">
          <div class="offcanvas-header d-lg-block py-3 p-lg-0">
            <div class="d-flex align-items-center">
              <div class="h5 d-flex justify-content-center align-items-center flex-shrink-0 text-primary bg-primary-subtle lh-1 rounded-circle mb-0" style="width: 3rem; height: 3rem">
                <?php echo strtoupper(substr($userData['first_name'], 0, 1)); ?>
              </div>
              <div class="min-w-0 ps-3">
                <h5 class="h6 mb-1"><?php echo htmlspecialchars($userData['first_name'] . ' ' . $userData['last_name']); ?></h5>
                <div class="nav flex-nowrap text-nowrap min-w-0">
                  <a class="nav-link animate-underline text-body p-0" href="#bonusesModal" data-bs-toggle="modal">
                    <svg class="text-warning flex-shrink-0 me-2" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M1.333 9.667H7.5V16h-5c-.64 0-1.167-.527-1.167-1.167V9.667zm13.334 0v5.167c0 .64-.527 1.167-1.167 1.167h-5V9.667h6.167zM0 5.833V7.5c0 .64.527 1.167 1.167 1.167h.167H7.5v-1-3H1.167C.527 4.667 0 5.193 0 5.833zm14.833-1.166H8.5v3 1h6.167.167C15.473 8.667 16 8.14 16 7.5V5.833c0-.64-.527-1.167-1.167-1.167z"/><path d="M8 5.363a.5.5 0 0 1-.495-.573C7.752 3.123 9.054-.03 12.219-.03c1.807.001 2.447.977 2.447 1.813 0 1.486-2.069 3.58-6.667 3.58zM12.219.971c-2.388 0-3.295 2.27-3.595 3.377 1.884-.088 3.072-.565 3.756-.971.949-.563 1.287-1.193 1.287-1.595 0-.599-.747-.811-1.447-.811z"/><path d="M8.001 5.363c-4.598 0-6.667-2.094-6.667-3.58 0-.836.641-1.812 2.448-1.812 3.165 0 4.467 3.153 4.713 4.819a.5.5 0 0 1-.495.573zM3.782.971c-.7 0-1.448.213-1.448.812 0 .851 1.489 2.403 5.042 2.566C7.076 3.241 6.169.971 3.782.971z"/></svg>
                    <span class="animate-target me-1"><?php echo number_format($userData['loyalty_points'] ?? 0); ?> puncte</span>
                    <span class="text-body fw-normal text-truncate">disponibile</span>
                  </a>
                </div>
              </div>
            </div>
            <button type="button" class="btn-close d-lg-none" data-bs-dismiss="offcanvas" data-bs-target="#accountSidebar" aria-label="Close"></button>
          </div>
          <div class="offcanvas-body d-block pt-2 pt-lg-4 pb-lg-0">
            <nav class="list-group list-group-borderless">
              <a class="list-group-item list-group-item-action d-flex align-items-center" href="/cont/comenzi">
                <i class="ci-shopping-bag fs-base opacity-75 me-2"></i>
                Comenzi
              </a>
              <a class="list-group-item list-group-item-action d-flex align-items-center" href="/cont/wishlist">
                <i class="ci-heart fs-base opacity-75 me-2"></i>
                Lista de dorințe
              </a>
              <a class="list-group-item list-group-item-action d-flex align-items-center" href="/cont/plata">
                <i class="ci-credit-card fs-base opacity-75 me-2"></i>
                Metode de plată
              </a>
              <a class="list-group-item list-group-item-action d-flex align-items-center" href="/cont/recenzii">
                <i class="ci-star fs-base opacity-75 me-2"></i>
                Recenziile mele
              </a>
            </nav>
            <h6 class="pt-4 ps-2 ms-1">Gestionare cont</h6>
            <nav class="list-group list-group-borderless">
              <a class="list-group-item list-group-item-action d-flex align-items-center" href="/cont/info">
                <i class="ci-user fs-base opacity-75 me-2"></i>
                Informații personale
              </a>
              <a class="list-group-item list-group-item-action d-flex align-items-center" href="/cont/adrese">
                <i class="ci-map-pin fs-base opacity-75 me-2"></i>
                Adrese
              </a>
              <a class="list-group-item list-group-item-action d-flex align-items-center pe-none active" href="/cont/notificari">
                <i class="ci-bell fs-base opacity-75 mt-1 me-2"></i>
                Notificări
              </a>
            </nav>
            <h6 class="pt-4 ps-2 ms-1">Servicii clienți</h6>
            <nav class="list-group list-group-borderless">
              <a class="list-group-item list-group-item-action d-flex align-items-center" href="/contact">
                <i class="ci-help-circle fs-base opacity-75 me-2"></i>
                Centru de ajutor
              </a>
            </nav>
            <nav class="list-group list-group-borderless pt-3">
              <a class="list-group-item list-group-item-action d-flex align-items-center" href="/api/auth.php?action=logout">
                <i class="ci-log-out fs-base opacity-75 me-2"></i>
                Deconectare
              </a>
            </nav>
          </div>
        </div>
      </aside>

      <!-- Notifications content -->
      <div class="col-lg-9">
        <div class="ps-lg-3 ps-xl-0">
          <h1 class="h2 pb-2 pb-md-3">Notificări</h1>

          <?php if ($message): ?>
          <div class="alert alert-success alert-dismissible fade show" role="alert">
            <?php echo htmlspecialchars($message); ?>
            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
          </div>
          <?php endif; ?>
          <?php if ($error): ?>
          <div class="alert alert-danger alert-dismissible fade show" role="alert">
            <?php echo htmlspecialchars($error); ?>
            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
          </div>
          <?php endif; ?>

          <form method="POST">
            <input type="hidden" name="action" value="update_notifications">
            
            <h2 class="h6 pt-5 mt-md-2">Preferințe notificări</h2>
            <div class="d-flex flex-column gap-3">
              <div class="form-check form-switch">
                <input type="checkbox" class="form-check-input" id="order-updates" name="order_updates" checked>
                <label class="form-check-label ps-2" for="order-updates">
                  <span class="d-block h6 mb-2">Actualizări comandă</span>
                  <span class="fs-sm">Primește notificări despre statusul comenzilor tale, inclusiv confirmări, actualizări de expediere și livrare.</span>
                </label>
              </div>
              <div class="form-check form-switch">
                <input type="checkbox" class="form-check-input" id="promotions" name="promotions" checked>
                <label class="form-check-label ps-2" for="promotions">
                  <span class="d-block h6 mb-2">Promoții și oferte</span>
                  <span class="fs-sm">Fii primul care află despre reduceri exclusive, oferte speciale și promoții sezoniere.</span>
                </label>
              </div>
              <div class="form-check form-switch">
                <input type="checkbox" class="form-check-input" id="account-security" name="account_security" checked>
                <label class="form-check-label ps-2" for="account-security">
                  <span class="d-block h6 mb-2">Alarme securitate cont</span>
                  <span class="fs-sm">Primește notificări despre orice activitate suspectă a contului sau modificări ale credențialelor de autentificare pentru securitate sporită.</span>
                </label>
              </div>
              <div class="form-check form-switch">
                <input type="checkbox" class="form-check-input" id="support" name="support">
                <label class="form-check-label ps-2" for="support">
                  <span class="d-block h6 mb-2">Actualizări suport clienți</span>
                  <span class="fs-sm">Primește actualizări despre orice întrebări sau tichete de suport pe care le-ai trimis, asigurând rezolvarea la timp a problemelor.</span>
                </label>
              </div>
            </div>

            <h2 class="h6 pt-5 mt-md-2">Canale de comunicare</h2>
            <div class="d-flex flex-column gap-2">
              <div class="form-check">
                <input type="checkbox" class="form-check-input" id="sms" name="sms">
                <label for="sms" class="form-check-label">SMS</label>
              </div>
              <div class="form-check">
                <input type="checkbox" class="form-check-input" id="whatsapp" name="whatsapp">
                <label for="whatsapp" class="form-check-label">Mesaje în WhatsApp</label>
              </div>
              <div class="form-check">
                <input type="checkbox" class="form-check-input" id="email" name="email" checked>
                <label for="email" class="form-check-label">Email</label>
              </div>
              <div class="form-check">
                <input type="checkbox" class="form-check-input" id="push" name="push">
                <label for="push" class="form-check-label">Notificări push aplicație</label>
              </div>
            </div>

            <div class="pt-4 mt-2">
              <button type="submit" class="btn btn-primary">Salvează modificări</button>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</main>

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

