{% extends "base.html" %}

{% block title %}{{ 'New Client' if not client else 'Edit Client' }} · Delphi Database{% endblock %}

{% block content %}
<div class="row g-3">
  <div class="col-12 d-flex align-items-center">
    <a class="btn btn-sm btn-outline-secondary me-2" href="/rolodex">
      <i class="bi bi-arrow-left"></i>
      Back
    </a>
    <h2 class="mb-0">{{ 'New Client' if not client else 'Edit Client' }}</h2>
  </div>

  <div class="col-12">
    <div class="card">
      <div class="card-body">
        <form method="post" action="{{ '/rolodex/create' if not client else '/rolodex/' ~ client.id ~ '/update' }}">
          <div class="mb-2 text-muted small" id="fieldHelp" aria-live="polite">Focus a field to see help.</div>
          <div class="row g-3">
            <div class="col-md-4">
              <label for="last_name" class="form-label">Last Name</label>
              <input type="text" class="form-control" id="last_name" name="last_name" data-help="Client last name (surname)." value="{{ client.last_name if client else '' }}">
            </div>
            <div class="col-md-4">
              <label for="first_name" class="form-label">First Name</label>
              <input type="text" class="form-control" id="first_name" name="first_name" data-help="Client given name." value="{{ client.first_name if client else '' }}">
            </div>
            <div class="col-md-4">
              <label for="company" class="form-label">Company</label>
              <input type="text" class="form-control" id="company" name="company" data-help="Organization or employer (optional)." value="{{ client.company if client else '' }}">
            </div>

            <div class="col-md-6">
              <label for="address" class="form-label">Address</label>
              <input type="text" class="form-control" id="address" name="address" value="{{ client.address if client else '' }}">
            </div>
            <div class="col-md-3">
              <label for="city" class="form-label">City</label>
              <input type="text" class="form-control" id="city" name="city" data-help="City or locality." value="{{ client.city if client else '' }}">
            </div>
            <div class="col-md-1">
              <label for="state" class="form-label">State</label>
              <input type="text" class="form-control" id="state" name="state" data-help="2-letter state code (e.g., NY)." value="{{ client.state if client else '' }}">
            </div>
            <div class="col-md-2">
              <label for="zip_code" class="form-label">ZIP</label>
              <input type="text" class="form-control" id="zip_code" name="zip_code" data-help="5-digit ZIP or ZIP+4." value="{{ client.zip_code if client else '' }}">
            </div>

            <div class="col-md-4">
              <label for="rolodex_id" class="form-label">Legacy Rolodex Id</label>
              <input type="text" class="form-control" id="rolodex_id" name="rolodex_id" data-help="Legacy ID used for migration and lookup; may be alphanumeric." value="{{ client.rolodex_id if client else '' }}">
            </div>

            <div class="col-12">
              <div class="d-flex gap-2">
                <button type="submit" class="btn btn-primary">
                  <i class="bi bi-check-lg me-1"></i>Save
                </button>
                <a href="{{ '/rolodex/' ~ client.id if client else '/rolodex' }}" class="btn btn-outline-secondary">Cancel</a>
              </div>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
</div>
{% endblock %}


