<?php
require_once __DIR__ . '/../../app/core/bootstrap.php';
require_once __DIR__ . '/../../app/core/project_permissions.php';
auth_require_login();
$pdo = crm_pdo();

if (!gp_can_manage_project_access($pdo)) {
    redirect('/gopools/public/dashboard/index.php');
}

$page_title = 'Settings Center';

// Stats for the "Command Center" feel
$userCount = (int)$pdo->query("SELECT COUNT(*) FROM users")->fetchColumn();
$logCount = (int)$pdo->query("SELECT COUNT(*) FROM system_logs")->fetchColumn();
$activeProjects = (int)$pdo->query("SELECT COUNT(*) FROM projects WHERE status IN ('active','planned','in_progress')")->fetchColumn();

include __DIR__ . '/../includes/header.php';
?>
<div class="page-header">
  <div class="page-header-title">
    <h1>Settings Center</h1>
    <span>Global system configuration & brand orchestration</span>
  </div>
</div>

<div class="card card-static" style="margin-bottom:32px; padding:0; overflow:hidden;">
  <div style="display:grid; grid-template-columns: repeat(3, 1fr); border-radius:var(--radius);">
    <!-- Cube 1: Users -->
    <div style="text-align:center; padding:32px 20px; border-right:1px solid var(--gp-card-border); transition:all 0.3s;" class="stat-cube">
      <div style="width:48px; height:48px; background:linear-gradient(135deg, #3b82f6, #2563eb); border-radius:12px; display:flex; align-items:center; justify-content:center; margin:0 auto 12px; font-size:1.4rem; color:white; box-shadow:0 8px 16px rgba(37,99,235,0.2);">👥</div>
      <div style="font-size:1.75rem; font-weight:800; color:var(--gp-text); line-height:1;"><?php echo $userCount; ?></div>
      <div style="font-size:0.72rem; color:var(--gp-muted); text-transform:uppercase; letter-spacing:0.08em; font-weight:700; margin-top:8px;">Active Users</div>
    </div>
    <!-- Cube 2: Projects -->
    <div style="text-align:center; padding:32px 20px; border-right:1px solid var(--gp-card-border); transition:all 0.3s;" class="stat-cube">
      <div style="width:48px; height:48px; background:linear-gradient(135deg, #10b981, #059669); border-radius:12px; display:flex; align-items:center; justify-content:center; margin:0 auto 12px; font-size:1.4rem; color:white; box-shadow:0 8px 16px rgba(16,185,129,0.2);">📈</div>
      <div style="font-size:1.75rem; font-weight:800; color:var(--gp-text); line-height:1;"><?php echo $activeProjects; ?></div>
      <div style="font-size:0.72rem; color:var(--gp-muted); text-transform:uppercase; letter-spacing:0.08em; font-weight:700; margin-top:8px;">Live Projects</div>
    </div>
    <!-- Cube 3: Events -->
    <div style="text-align:center; padding:32px 20px; transition:all 0.3s;" class="stat-cube">
      <div style="width:48px; height:48px; background:linear-gradient(135deg, #f59e0b, #d97706); border-radius:12px; display:flex; align-items:center; justify-content:center; margin:0 auto 12px; font-size:1.4rem; color:white; box-shadow:0 8px 16px rgba(245,158,11,0.2);">📜</div>
      <div style="font-size:1.75rem; font-weight:800; color:var(--gp-text); line-height:1;"><?php echo number_format($logCount); ?></div>
      <div style="font-size:0.72rem; color:var(--gp-muted); text-transform:uppercase; letter-spacing:0.08em; font-weight:700; margin-top:8px;">System Events</div>
    </div>
  </div>
</div>

<style>
.stat-cube:hover { background: rgba(0,0,0,0.02); }
[data-theme='dark'] .stat-cube:hover { background: rgba(255,255,255,0.02); }
@media (max-width: 768px) {
  .stat-cube { border-right:none !important; border-bottom:1px solid var(--gp-card-border); }
  .stat-cube:last-child { border-bottom:none; }
  .card div[style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
}
</style>

<div class="grid-2">
  
  <!-- Branding & Experience -->
  <div class="card card-static">
    <div style="display:flex; align-items:center; gap:16px; margin-bottom:20px;">
      <div style="font-size:2.2rem;">🎨</div>
      <div style="flex:1;">
        <h2 style="font-size:1.15rem; margin:0;">Branding & Identity</h2>
        <span style="font-size:0.85rem; color:var(--gp-muted);">Logo, typography, colors, and global UI architecture</span>
      </div>
    </div>
    <div style="display:flex; flex-direction:column; gap:8px;">
      <a href="/gopools/public/settings/branding.php" class="btn btn-secondary btn-sm" style="justify-content:space-between;">
        <span>Configure Visual Identity</span>
        <span>→</span>
      </a>
      <div class="small" style="color:var(--gp-muted); margin-top:4px; padding-left:4px;">
        • Logo sizing & alignment<br>
        • Dynamic font selection<br>
        • Glassmorphism control
      </div>
    </div>
  </div>

  <!-- User & Access Control -->
  <div class="card card-static">
    <div style="display:flex; align-items:center; gap:16px; margin-bottom:20px;">
      <div style="font-size:2.2rem;">🔑</div>
      <div style="flex:1;">
        <h2 style="font-size:1.15rem; margin:0;">Users & Security</h2>
        <span style="font-size:0.85rem; color:var(--gp-muted);">Manage team access, roles, and guest portal permissions</span>
      </div>
    </div>
    <div style="display:flex; flex-direction:column; gap:8px;">
      <a href="/gopools/public/settings/users.php" class="btn btn-secondary btn-sm" style="justify-content:space-between;">
        <span>Manage Accounts</span>
        <span>→</span>
      </a>
      <a href="/gopools/public/settings/user_invites.php" class="btn btn-secondary btn-sm" style="justify-content:space-between;">
        <span>Pending Invites</span>
        <span>→</span>
      </a>
    </div>
  </div>

  <!-- Communication & Email -->
  <div class="card card-static">
    <div style="display:flex; align-items:center; gap:16px; margin-bottom:20px;">
      <div style="font-size:2.2rem;">📬</div>
      <div style="flex:1;">
        <h2 style="font-size:1.15rem; margin:0;">Email & Automation</h2>
        <span style="font-size:0.85rem; color:var(--gp-muted);">SMTP server, incoming mailbox syncing, and automation triggers</span>
      </div>
    </div>
    <div style="display:flex; flex-direction:column; gap:8px;">
      <a href="/gopools/public/settings/smtp.php" class="btn btn-secondary btn-sm" style="justify-content:space-between;">
        <span>Outgoing Server (SMTP)</span>
        <span>→</span>
      </a>
      <a href="/gopools/public/settings/email_to_project.php" class="btn btn-secondary btn-sm" style="justify-content:space-between;">
        <span>Email-to-Project Pipeline</span>
        <span>→</span>
      </a>
    </div>
  </div>

  <!-- System Governance -->
  <div class="card card-static">
    <div style="display:flex; align-items:center; gap:16px; margin-bottom:20px;">
      <div style="font-size:2.2rem;">🛡️</div>
      <div style="flex:1;">
        <h2 style="font-size:1.15rem; margin:0;">System Governance</h2>
        <span style="font-size:0.85rem; color:var(--gp-muted);">Project statuses, logging, and infrastructure cleanup tools</span>
      </div>
    </div>
    <div style="display:flex; flex-direction:column; gap:8px;">
      <a href="/gopools/public/settings/logs.php" class="btn btn-secondary btn-sm" style="justify-content:space-between;">
        <span>System Activity Logs</span>
        <span>→</span>
      </a>
      <a href="/gopools/public/settings/project_statuses.php" class="btn btn-secondary btn-sm" style="justify-content:space-between;">
        <span>Project Lifecycle States</span>
        <span>→</span>
      </a>
      <a href="/gopools/public/settings/general.php" class="btn btn-primary btn-sm" style="justify-content:space-between; margin-top:8px;">
        <span>General System Settings</span>
        <span>→</span>
      </a>
    </div>
  </div>

</div>

<?php include __DIR__ . '/../includes/header.php'; ?>
