{% extends 'base.html' %}
{% block content %}
  <div style="display:flex;justify-content:space-between;align-items:center;">
    <h2>Edit Account - {{ account.name }}</h2>
    <a class="btn-outline" href="{{ url_for('list_accounts') }}">Back to Accounts</a>
  </div>
  
  <div class="card" style="margin-top:8px">
    <form method="post" class="form">
      {{ form.hidden_tag() }}
      <div class="field">
        <label class="label">Name <span style="color: #dc2626;">*</span></label>
        {{ form.name() }}
        {% if form.name.errors %}
          <div class="error">{{ form.name.errors[0] }}</div>
        {% endif %}
      </div>
      <div class="field">
        <label class="label">Account Holder</label>
        {{ form.holder_name() }}
        {% if form.holder_name.errors %}
          <div class="error">{{ form.holder_name.errors[0] }}</div>
        {% endif %}
      </div>
      <div class="grid cols-2">
        <div class="field">
          <label class="label">Account Number</label>
          {{ form.account_number() }}
          {% if form.account_number.errors %}
            <div class="error">{{ form.account_number.errors[0] }}</div>
          {% endif %}
        </div>
        <div class="field">
          <label class="label">Phone</label>
          {{ form.phone() }}
          {% if form.phone.errors %}
            <div class="error">{{ form.phone.errors[0] }}</div>
          {% endif %}
        </div>
      </div>
      <div class="grid cols-2">
        <div class="field">
          <label class="label">Bank/Provider</label>
          {{ form.bank_name() }}
          {% if form.bank_name.errors %}
            <div class="error">{{ form.bank_name.errors[0] }}</div>
          {% endif %}
        </div>
        <div class="field">
          <label class="label">Branch</label>
          {{ form.branch() }}
          {% if form.branch.errors %}
            <div class="error">{{ form.branch.errors[0] }}</div>
          {% endif %}
        </div>
      </div>
      <div class="grid cols-2">
        <div class="field">
          <label class="label">IFSC/SWIFT</label>
          {{ form.ifsc_swift() }}
          {% if form.ifsc_swift.errors %}
            <div class="error">{{ form.ifsc_swift.errors[0] }}</div>
          {% endif %}
        </div>
        <div class="field">
          <label class="label">Opening Balance</label>
          {{ form.opening_balance(step='0.01') }}
          {% if form.opening_balance.errors %}
            <div class="error">{{ form.opening_balance.errors[0] }}</div>
          {% endif %}
          <small style="color: #666;">Note: Changing opening balance will affect account balance calculations</small>
        </div>
      </div>
      <div class="field">
        <label class="label">Type <span style="color: #dc2626;">*</span></label>
        {{ form.type() }}
        {% if form.type.errors %}
          <div class="error">{{ form.type.errors[0] }}</div>
        {% endif %}
      </div>
      
      <!-- Online Payment Settings -->
      <div class="card" style="margin: 16px 0; padding: 16px; background-color: #f9fafb; border: 1px solid #e5e7eb;">
        <h4 style="margin: 0 0 12px 0;">Online Payment Settings</h4>
        <div class="field">
          <label class="label">Enable Online Payment</label>
          <div style="display: flex; gap: 16px; margin-top: 8px;">
            {% for choice in form.is_online_payment_enabled %}
              <label style="display: flex; align-items: center; gap: 8px; cursor: pointer;">
                {{ choice() }}
                <span>{{ choice.label.text }}</span>
              </label>
            {% endfor %}
          </div>
          <small style="color: #666;">If enabled, customers can see this account for online payments</small>
        </div>
        <div class="field">
          <label class="label">Payment Instructions</label>
          {{ form.payment_instructions(placeholder="e.g., Please include your name in payment description") }}
          {% if form.payment_instructions.errors %}
            <div class="error">{{ form.payment_instructions.errors[0] }}</div>
          {% endif %}
          <small style="color: #666;">Instructions for customers making payments to this account</small>
        </div>
      </div>
      
      <div class="field">
        <label class="label">Note</label>
        {{ form.note() }}
        {% if form.note.errors %}
          <div class="error">{{ form.note.errors[0] }}</div>
        {% endif %}
      </div>
      <div style="display: flex; gap: 8px;">
        {{ form.submit(class_='btn-primary') }}
        <a class="btn-outline" href="{{ url_for('list_accounts') }}">Cancel</a>
      </div>
    </form>
  </div>
  
  <!-- Warning about transactions -->
  <div class="card" style="margin-top: 16px; background-color: #fef3c7; border: 1px solid #fbbf24;">
    <h4 style="margin: 0 0 8px 0; color: #92400e;">⚠️ Important Notes</h4>
    <ul style="margin: 0; padding-left: 20px; color: #78350f;">
      <li>Changing the opening balance will affect all balance calculations</li>
      <li>Account type changes may affect how the account is displayed</li>
      <li>If this account has transactions, they will remain linked to this account</li>
    </ul>
  </div>
{% endblock %}

