{% extends "base.html" %}
{% block title %}{{ 'Bearbeiten' if kontakt else 'Neue Organisation' }}{{ " - " + app_name() }}{% endblock %}

{% block content %}
<div class="page-header">
    <h1>{% if kontakt %}{{ kontakt.anzeigename }} bearbeiten{% else %}Neue Organisation{% endif %}</h1>
</div>

<form method="post" action="{% if kontakt %}/kontakte/{{ kontakt.id }}/bearbeiten{% else %}/organisationen/neu{% endif %}">
    <input type="hidden" name="typ" value="organisation">

    <div class="card">
        <div class="card-header"><h3>Organisationsdaten</h3></div>
        <div class="form-grid">
            <div>
                <label for="firmenname">Name *</label>
                <input type="text" id="firmenname" name="firmenname" value="{{ kontakt.firmenname if kontakt else '' }}" required>
            </div>
            <div>
                <label for="firmenname2">Zusatzname</label>
                <input type="text" id="firmenname2" name="firmenname2" value="{{ kontakt.firmenname2 if kontakt else '' }}">
            </div>
        </div>
    </div>

    <div class="card">
        <div class="card-header"><h3>Adresse</h3></div>
        <div class="form-grid">
            <div class="full-width">
                <label for="strasse">Straße</label>
                <input type="text" id="strasse" name="strasse" value="{{ kontakt.strasse if kontakt else '' }}">
            </div>
            <div>
                <label for="plz">PLZ</label>
                <input type="text" id="plz" name="plz" value="{{ kontakt.plz if kontakt else '' }}" maxlength="10">
            </div>
            <div>
                <label for="ort">Ort</label>
                <input type="text" id="ort" name="ort" value="{{ kontakt.ort if kontakt else '' }}">
            </div>
            <div>
                <label for="land">Land</label>
                <input type="text" id="land" name="land" value="{{ kontakt.land if kontakt else 'Deutschland' }}">
            </div>
        </div>
    </div>

    <div class="card">
        <div class="card-header"><h3>Kontaktdaten</h3></div>
        <div class="form-grid">
            <div>
                <label for="email1">E-Mail</label>
                <input type="email" id="email1" name="email1" value="{{ kontakt.email1 if kontakt else '' }}">
            </div>
            <div>
                <label for="telefon">Telefon</label>
                <input type="tel" id="telefon" name="telefon" value="{{ kontakt.telefon if kontakt else '' }}">
            </div>
            <div>
                <label for="telefax">Fax</label>
                <input type="tel" id="telefax" name="telefax" value="{{ kontakt.telefax if kontakt else '' }}">
            </div>
            <div>
                <label for="webseite">Webseite</label>
                <input type="url" id="webseite" name="webseite" value="{{ kontakt.webseite if kontakt else '' }}">
            </div>
        </div>
    </div>

    <div class="card">
        <div class="card-header"><h3>Sonstiges</h3></div>
        <div class="form-grid">
            <div class="full-width">
                <label for="bemerkung">Bemerkung</label>
                <textarea id="bemerkung" name="bemerkung" rows="4">{{ kontakt.bemerkung if kontakt else '' }}</textarea>
            </div>
        </div>
    </div>

    <div class="btn-group" style="margin-top: 1rem;">
        <button type="submit">💾 Speichern</button>
        <a href="{% if kontakt %}/kontakte/{{ kontakt.id }}{% else %}/organisationen{% endif %}" role="button" class="outline">Abbrechen</a>
    </div>
</form>
{% endblock %}
