{% extends "admin/base_admin.html" %}
{% set admin_page = "leads" %}
{% block title %}New Lead - Admin - {{ config.APP_NAME }}{% endblock %}

{% block admin_content %}
<div style="max-width:720px">
  <a href="{{ url_for('admin.leads') }}" class="text-sm text-slate">&larr; All Leads</a>
  <h1 class="text-2xl mt-2 mb-6">Create Lead</h1>

  <form method="post" class="card" style="padding:1.5rem">
    <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">

    <h2 class="text-lg mb-3">Contact</h2>
    <div style="display:grid;grid-template-columns:1fr 1fr;gap:1rem;margin-bottom:1rem">
      <div>
        <label class="form-label">Full Name *</label>
        <input type="text" name="contact_name" class="form-input" required value="{{ data.get('contact_name', '') }}">
      </div>
      <div>
        <label class="form-label">Email *</label>
        <input type="email" name="contact_email" class="form-input" required value="{{ data.get('contact_email', '') }}">
      </div>
    </div>
    <div style="display:grid;grid-template-columns:1fr 1fr 1fr;gap:1rem;margin-bottom:1rem">
      <div>
        <label class="form-label">Phone</label>
        <input type="text" name="contact_phone" class="form-input" value="{{ data.get('contact_phone', '') }}">
      </div>
      <div>
        <label class="form-label">Company</label>
        <input type="text" name="contact_company" class="form-input" value="{{ data.get('contact_company', '') }}">
      </div>
      <div>
        <label class="form-label">Role</label>
        <select name="stakeholder_type" class="form-input">
          {% for v in ['entrepreneur','tennis_club','municipality','developer','operator','architect'] %}
          <option value="{{ v }}" {{ 'selected' if data.get('stakeholder_type') == v }}>{{ v | replace('_', ' ') | title }}</option>
          {% endfor %}
        </select>
      </div>
    </div>

    <hr style="margin:1.5rem 0">

    <h2 class="text-lg mb-3">Project</h2>
    <div style="display:grid;grid-template-columns:1fr 1fr 1fr;gap:1rem;margin-bottom:1rem">
      <div>
        <label class="form-label">Facility Type *</label>
        <select name="facility_type" class="form-input" required>
          {% for v in ['indoor','outdoor','both'] %}
          <option value="{{ v }}" {{ 'selected' if data.get('facility_type', 'indoor') == v }}>{{ v | title }}</option>
          {% endfor %}
        </select>
      </div>
      <div>
        <label class="form-label">Build Context</label>
        <select name="build_context" class="form-input">
          <option value="">—</option>
          {% for v in ['new_build','conversion','expansion'] %}
          <option value="{{ v }}" {{ 'selected' if data.get('build_context') == v }}>{{ v | replace('_', ' ') | title }}</option>
          {% endfor %}
        </select>
      </div>
      <div>
        <label class="form-label">Courts</label>
        <input type="number" name="court_count" class="form-input" min="1" max="50" value="{{ data.get('court_count', '6') }}">
      </div>
    </div>

    <div style="display:grid;grid-template-columns:1fr 1fr;gap:1rem;margin-bottom:1rem">
      <div>
        <label class="form-label">Glass Type</label>
        <select name="glass_type" class="form-input">
          <option value="">—</option>
          {% for v in ['tempered','standard'] %}
          <option value="{{ v }}" {{ 'selected' if data.get('glass_type') == v }}>{{ v | title }}</option>
          {% endfor %}
        </select>
      </div>
      <div>
        <label class="form-label">Lighting</label>
        <select name="lighting_type" class="form-input">
          <option value="">—</option>
          {% for v in ['led','standard','none'] %}
          <option value="{{ v }}" {{ 'selected' if data.get('lighting_type') == v }}>{{ v | title }}</option>
          {% endfor %}
        </select>
      </div>
    </div>

    <div style="display:grid;grid-template-columns:1fr 1fr;gap:1rem;margin-bottom:1rem">
      <div>
        <label class="form-label">Country *</label>
        <select name="country" class="form-input" required>
          {% for code, name in [('DE','Germany'),('ES','Spain'),('IT','Italy'),('FR','France'),('NL','Netherlands'),('SE','Sweden'),('GB','United Kingdom'),('PT','Portugal'),('AE','UAE'),('SA','Saudi Arabia')] %}
          <option value="{{ code }}" {{ 'selected' if data.get('country') == code }}>{{ name }}</option>
          {% endfor %}
        </select>
      </div>
      <div>
        <label class="form-label">City</label>
        <input type="text" name="city" class="form-input" value="{{ data.get('city', '') }}">
      </div>
    </div>

    <div style="display:grid;grid-template-columns:1fr 1fr;gap:1rem;margin-bottom:1rem">
      <div>
        <label class="form-label">Location Status</label>
        <select name="location_status" class="form-input">
          <option value="">—</option>
          {% for v in ['secured','searching','evaluating'] %}
          <option value="{{ v }}" {{ 'selected' if data.get('location_status') == v }}>{{ v | title }}</option>
          {% endfor %}
        </select>
      </div>
      <div>
        <label class="form-label">Timeline *</label>
        <select name="timeline" class="form-input" required>
          {% for v, label in [('asap','ASAP'),('3-6mo','3–6 Months'),('6-12mo','6–12 Months'),('12+mo','12+ Months')] %}
          <option value="{{ v }}" {{ 'selected' if data.get('timeline') == v }}>{{ label }}</option>
          {% endfor %}
        </select>
      </div>
    </div>

    <div style="display:grid;grid-template-columns:1fr 1fr;gap:1rem;margin-bottom:1rem">
      <div>
        <label class="form-label">Budget (€)</label>
        <input type="number" name="budget_estimate" class="form-input" value="{{ data.get('budget_estimate', '') }}">
      </div>
      <div>
        <label class="form-label">Financing Status</label>
        <select name="financing_status" class="form-input">
          <option value="">—</option>
          {% for v in ['secured','in_progress','not_started'] %}
          <option value="{{ v }}" {{ 'selected' if data.get('financing_status') == v }}>{{ v | replace('_', ' ') | title }}</option>
          {% endfor %}
        </select>
      </div>
    </div>

    <div style="margin-bottom:1rem">
      <label class="form-label">Services Needed</label>
      <input type="text" name="services_needed" class="form-input" placeholder="e.g. construction, consulting, equipment"
             value="{{ data.get('services_needed', '') }}">
    </div>

    <div style="margin-bottom:1rem">
      <label class="form-label">Additional Info</label>
      <textarea name="additional_info" class="form-input" rows="3" style="width:100%">{{ data.get('additional_info', '') }}</textarea>
    </div>

    <hr style="margin:1.5rem 0">

    <h2 class="text-lg mb-3">Classification</h2>
    <div style="display:grid;grid-template-columns:1fr 1fr;gap:1rem;margin-bottom:1.5rem">
      <div>
        <label class="form-label">Heat Score</label>
        <select name="heat_score" class="form-input">
          {% for v in ['hot','warm','cool'] %}
          <option value="{{ v }}" {{ 'selected' if data.get('heat_score', 'warm') == v }}>{{ v | title }}</option>
          {% endfor %}
        </select>
      </div>
      <div>
        <label class="form-label">Status</label>
        <select name="status" class="form-input">
          {% for s in statuses %}
          <option value="{{ s }}" {{ 'selected' if s == 'new' }}>{{ s | replace('_', ' ') }}</option>
          {% endfor %}
        </select>
      </div>
    </div>

    <button type="submit" class="btn" style="width:100%">Create Lead</button>
  </form>
</div>
{% endblock %}
