<?php
session_start();
require 'config.php';

// Security check (Taki bina login koi access na kar sake)
if (!isset($_SESSION['admin_logged_in'])) {
    header("Location: login.php");
    exit;
}

if ($_SERVER["REQUEST_METHOD"] === "POST") {
    $stmt = $dbh->prepare("INSERT INTO ea_tools (category, title, income_last_year, description, price, old_price) VALUES (?, ?, ?, ?, ?, ?)");
    $stmt->execute([
        $_POST['category'],
        $_POST['title'],
        $_POST['income'],
        $_POST['description'],
        $_POST['price'],
        $_POST['old_price']
    ]);
    header("Location: view_ea.php");
    exit;
}

// Include Premium Admin Header & Sidebar
include "includes/header.php";
include "includes/sidebar.php";
?>

<style>
  /* ── Layout & Page Header ── */
  .dash { max-width: 900px; margin: 0 auto; padding: 30px 26px; z-index: 1; position: relative; }
  
  .page-header { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 28px; flex-wrap: wrap; gap: 14px; }
  .ph-eyebrow { font-family: 'JetBrains Mono', monospace; font-size: 0.6rem; letter-spacing: 3.5px; text-transform: uppercase; color: var(--yellow-dim); margin-bottom: 6px; display: flex; align-items: center; gap: 7px; }
  .ph-eyebrow::before { content: ''; display: inline-block; width: 20px; height: 2px; background: var(--yellow); border-radius: 2px; }
  .ph-title { font-family: 'Syne', sans-serif; font-size: 2rem; font-weight: 800; color: var(--text-1); letter-spacing: -0.5px; line-height: 1.1; }

  /* ── Form Panel ── */
  .form-panel { background: var(--dark-700); border: 1px solid rgba(255,255,255,0.05); border-radius: 14px; padding: 30px; }
  
  .section-title { font-family: 'Syne', sans-serif; font-size: 1.1rem; font-weight: 700; color: var(--text-1); border-bottom: 1px solid rgba(255,255,255,0.05); padding-bottom: 10px; margin-bottom: 20px; margin-top: 20px; }
  .section-title:first-child { margin-top: 0; }
  .section-title i { color: var(--yellow); margin-right: 8px; font-size: 1rem; }

  .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
  .grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }

  .form-group { margin-bottom: 18px; }
  .form-label { display: block; font-family: 'JetBrains Mono', monospace; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 1px; color: var(--text-2); margin-bottom: 8px; font-weight: 600; }
  
  .form-control { width: 100%; padding: 12px 16px; background: var(--dark-800); border: 1px solid rgba(255,255,255,0.08); border-radius: 8px; color: var(--text-1); font-size: 0.9rem; transition: 0.3s; font-family: 'Manrope', sans-serif; }
  .form-control:focus { outline: none; border-color: var(--yellow); box-shadow: 0 0 0 3px var(--yellow-glass); }
  .form-control::placeholder { color: rgba(255,255,255,0.2); }
  
  textarea.form-control { min-height: 100px; resize: vertical; }

  /* Custom Select Dropdown */
  .form-select { appearance: none; background-image: url('data:image/svg+xml;charset=US-ASCII,<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="%238a90a6" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"></polyline></svg>'); background-repeat: no-repeat; background-position: right 15px center; background-size: 14px; cursor: pointer; }
  .form-select option { background: var(--dark-800); color: var(--text-1); }

  /* ── Action Buttons ── */
  .form-actions { display: flex; gap: 15px; margin-top: 30px; padding-top: 20px; border-top: 1px solid rgba(255,255,255,0.05); }
  .btn-submit { background: var(--yellow); color: var(--dark-900); padding: 12px 28px; border: none; border-radius: 8px; font-weight: 700; font-size: 0.95rem; cursor: pointer; transition: 0.2s; display: flex; align-items: center; gap: 8px; }
  .btn-submit:hover { background: var(--yellow-bright); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(245,197,24,0.3); }
  
  .btn-cancel { background: rgba(255,255,255,0.05); color: var(--text-1); padding: 12px 28px; border: 1px solid rgba(255,255,255,0.1); border-radius: 8px; font-weight: 600; font-size: 0.95rem; cursor: pointer; text-decoration: none; transition: 0.2s; display: flex; align-items: center; gap: 8px; }
  .btn-cancel:hover { background: rgba(255,255,255,0.1); color: #fff; }

  /* Input Addon for currency/percentage */
  .input-group { position: relative; display: flex; align-items: center; }
  .input-group i { position: absolute; left: 15px; color: var(--text-3); font-size: 0.9rem; }
  .input-group .form-control { padding-left: 40px; }

  @media (max-width: 768px) {
      .grid-2, .grid-3 { grid-template-columns: 1fr; gap: 10px; }
      .form-actions { flex-direction: column; }
      .btn-submit, .btn-cancel { width: 100%; justify-content: center; }
  }
</style>

<main class="dash">

    <!-- Page Header -->
    <div class="page-header">
        <div>
            <div class="ph-eyebrow">Expert Advisors</div>
            <div class="ph-title">Add New <strong>EA Tool</strong></div>
        </div>
    </div>

    <!-- Form Panel -->
    <div class="form-panel">
        <form method="post" action="">

            <h3 class="section-title"><i class="fas fa-robot"></i> EA Tool Information</h3>
            
            <div class="grid-2">
                <div class="form-group">
                    <label class="form-label" for="title">Title</label>
                    <input type="text" id="title" name="title" class="form-control" placeholder="Enter EA title" required>
                </div>
                <div class="form-group">
                    <label class="form-label" for="category">Category</label>
                    <select id="category" name="category" class="form-control form-select" required>
                        <option value="Tools">Tools</option>
                        <option value="Martin">Martin</option>
                        <option value="Shock">Shock</option>
                        <option value="Trend">Trend</option>
                        <option value="Grid">Grid</option>
                        <option value="Comprehensive">Comprehensive</option>
                    </select>
                </div>
            </div>

            <div class="grid-3">
                <div class="form-group">
                    <label class="form-label" for="income">Income Last Year</label>
                    <div class="input-group">
                        <i class="fas fa-chart-line"></i>
                        <input type="text" id="income" name="income" class="form-control" placeholder="+120.00%">
                    </div>
                </div>
                <div class="form-group">
                    <label class="form-label" for="price">Current Price</label>
                    <div class="input-group">
                        <i class="fas fa-dollar-sign"></i>
                        <input type="text" id="price" name="price" class="form-control" placeholder="0.99">
                    </div>
                </div>
                <div class="form-group">
                    <label class="form-label" for="old_price">Old Price</label>
                    <div class="input-group">
                        <i class="fas fa-tag"></i>
                        <input type="text" id="old_price" name="old_price" class="form-control" placeholder="980.00">
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label class="form-label" for="description">Description</label>
                <textarea id="description" name="description" class="form-control" placeholder="Enter a short description of the EA..."></textarea>
            </div>

            <!-- Action Buttons -->
            <div class="form-actions">
                <button type="submit" class="btn-submit">
                    <i class="fas fa-plus-circle"></i> Add EA Tool
                </button>
                <a href="view_ea.php" class="btn-cancel">
                    <i class="fas fa-times"></i> Cancel
                </a>
            </div>

        </form>
    </div>

</main>

<?php include "includes/footer.php"; ?>