<?php
require_once __DIR__ . '/includes/settings_helpers.php';

settings_require_auth();
settings_ensure_tables($conn);
settings_get_current_org($conn);

$tab = trim((string) ($_GET['tab'] ?? 'email_alerts'));
$tabs = [
    'email_alerts' => 'Email Alerts',
    'webhooks' => 'Webhooks',
    'custom_functions' => 'Custom Functions',
    'schedules' => 'Schedules',
    'custom_button' => 'Custom Button',
];
if (!isset($tabs[$tab])) {
    $tab = 'email_alerts';
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
<base href="<?php echo billing_escape(billing_base_href()); ?>">
  <title>Workflow Logs | Settings</title>
  <link rel="stylesheet" href="assets/fontawesome/css/all.min.css">
  <link rel="stylesheet" href="assets/font-inter.css">
  <link rel="stylesheet" href="orgprofile.css">
  <style>
    .inner-tabs{display:flex;gap:32px;border-bottom:1px solid var(--border);margin-bottom:14px;flex-wrap:wrap;}
    .inner-tabs a{padding:0 0 14px;color:#2563eb;text-decoration:none;font-size:16px;}
    .inner-tabs a.active{color:#111827;border-bottom:3px solid #3b82f6;font-weight:600;}
    .filters{display:flex;gap:12px;flex-wrap:wrap;align-items:center;margin:14px 0 24px;}
    .filter-chip{display:inline-flex;align-items:center;gap:10px;padding:12px 14px;border:1px solid #d7dce7;border-radius:12px;background:#fff;}
    .empty-state{min-height:340px;display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;}
    .empty-state i{font-size:96px;color:#c7d2fe;margin-bottom:16px;}
    .empty-state h2{margin:0 0 12px;font-size:22px;}
    .empty-state p{font-size:18px;color:#6b7280;}
    .top-tools{display:flex;justify-content:space-between;gap:12px;flex-wrap:wrap;align-items:center;}
  </style>
</head>
<body class="orgprofile-page">
  <?php settings_render_header($_SESSION['org_name'] ?? 'demo', 'dashboard.php', 'fa-box-open'); ?>
  <main class="profile-layout">
    <?php settings_render_sidebar('workflow_logs'); ?>
    <section class="profile-main">
      <div class="profile-head"><h1>Workflow Logs</h1></div>
      <div class="profile-card">
        <div class="top-tools">
          <div class="inner-tabs">
            <?php foreach ($tabs as $tabKey => $label): ?>
              <a class="<?php echo $tabKey === $tab ? 'active' : ''; ?>" href="workflow_logs.php?tab=<?php echo urlencode($tabKey); ?>"><?php echo htmlspecialchars($label); ?></a>
            <?php endforeach; ?>
          </div>
          <div style="display:flex;gap:12px;align-items:center;">
            <?php if ($tab === 'email_alerts' || $tab === 'webhooks'): ?><a class="cancel-btn" href="#">Configure Failure Preferences</a><?php endif; ?>
            <a class="cancel-btn" href="#">Export</a>
          </div>
        </div>
        <div class="filters">
          <div class="filter-chip"><i class="fa-solid fa-filter"></i> Filter By:</div>
          <div class="filter-chip">Status <i class="fa-solid fa-angle-down"></i></div>
          <div class="filter-chip">Module <i class="fa-solid fa-angle-down"></i></div>
          <div class="filter-chip">Date Range</div>
          <div class="filter-chip">Last Thirty Days <i class="fa-solid fa-angle-down"></i></div>
          <a class="save-btn" href="#">Apply Filter</a>
        </div>
        <div class="empty-state">
          <i class="fa-regular fa-face-meh"></i>
          <p>There are no logs</p>
        </div>
      </div>
    </section>
  </main>
</body>
</html>

