{% extends "base.html" %}
{% block content %}
<div class="level">
    <div class="level-left">
        <h1 class="title is-3">{{ contract.name }}</h1>
        <span class="tag is-medium {{ 'is-success' if contract.status == 'Angenommen' else 'is-warning' if contract.status == 'Zur Prüfung' else 'is-light' }} ml-3">
            {{ contract.status }}
        </span>
    </div>
    <div class="level-right">
        <a class="button is-light" href="{{ url_for('contracts.index') }}">← Alle Verträge</a>
    </div>
</div>

<div class="columns">
    <div class="column is-4">
        <div class="box">
            <h2 class="title is-6">Details</h2>
            <form method="POST" action="{{ url_for('contracts.detail_update', contract_id=contract.id) }}">
                <div class="field">
                    <label class="label is-small">Belegnummer</label>
                    <div class="control"><input class="input is-small" name="belegnummer" value="{{ contract.belegnummer or '' }}"></div>
                </div>
                <div class="field">
                    <label class="label is-small">Beleg-Datum</label>
                    <div class="control"><input class="input is-small" type="date" name="beleg_datum" value="{{ contract.beleg_datum.strftime('%Y-%m-%d') if contract.beleg_datum else '' }}"></div>
                </div>
                <div class="field">
                    <label class="label is-small">Laufzeit Start</label>
                    <div class="control"><input class="input is-small" type="date" name="laufzeit_start" value="{{ contract.laufzeit_start.strftime('%Y-%m-%d') if contract.laufzeit_start else '' }}"></div>
                </div>
                <div class="field">
                    <label class="label is-small">Laufzeit Ende</label>
                    <div class="control"><input class="input is-small" type="date" name="laufzeit_ende" value="{{ contract.laufzeit_ende.strftime('%Y-%m-%d') if contract.laufzeit_ende else '' }}"></div>
                </div>
                <div class="field is-grouped">
                    <div class="control"><button class="button is-small is-info">Speichern</button></div>
                </div>
            </form>
            <form method="POST" action="{{ url_for('contracts.status_set', contract_id=contract.id) }}" class="mt-3">
                <div class="field has-addons">
                    <div class="control">
                        <div class="select is-small">
                            <select name="status">
                                <option value="NEU" {{ 'selected' if contract.status == 'NEU' }}>NEU</option>
                                <option value="Zur Prüfung" {{ 'selected' if contract.status == 'Zur Prüfung' }}>Zur Prüfung</option>
                                <option value="Angenommen" {{ 'selected' if contract.status == 'Angenommen' }}>Angenommen</option>
                            </select>
                        </div>
                    </div>
                    <div class="control">
                        <button class="button is-small is-info">Status setzen</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="column is-8">
        <div class="box">
            <h2 class="title is-6">Zugehörige Leistungsverzeichnisse</h2>
            {% if lv_names %}
            <ul>
                {% for name in lv_names %}
                <li><a href="{{ url_for('lv.index', lv=name) }}">{{ name }}</a></li>
                {% endfor %}
            </ul>
            {% else %}
            <p class="has-text-grey">Diesem Vertrag sind noch keine LVs zugeordnet.</p>
            {% endif %}
        </div>
    </div>
</div>

<form method="POST" action="{{ url_for('contracts.delete', contract_id=contract.id) }}"
      onsubmit="return confirm('Vertrag wirklich löschen?')" class="mt-3">
    <button class="button is-danger is-outlined is-small">Vertrag löschen</button>
</form>
{% endblock %}
