{% extends frame.html %}

{% block body %}
<div class="w3-container w3-blue"><h1>{% if report_type %}Edit{% else %}New{% end %} Report</h1></div>

<form id="report_add" class="w3-card w3-padding" action="{{request.path}}" method="POST">
    {% raw xsrf_form_html() %}
    {% if report_type %}
    <input type="hidden" name="report_type_id" value="{{report_type['report_type_id']}}"/>
    {% end %}

    {% if errors.get('sql_error') %}
    <pre class="w3-text-red">{{errors['sql_error']}}</pre>
    {% end %}

    <p>
        <label><b>Report Name</b> {% if errors.get('report_type_name') %}<span class="w3-text-red">{{errors['report_type_name']}}</span>{% end %}</label>
        <input class="w3-input" type="text" name="report_type_name" value="{{report_type.get('report_type_name', '')}}" placeholder="ie 'Key Metrics'" />
    </p>

    {% if schemas %}
    <p>
        <label><b>Report Schema</b> {% if errors.get('report_schema') %}<span class="w3-text-red">{{errors['report_schema']}}</span>{% end %}</label>
        <select class="w3-input" name="report_schema">
            {% for schema in schemas %}
            <option value="{{schema}}" {% if report_type and report_type['report_schema'] == schema %}selected="selected"{% end %}>{{schema}}</option>
            {% end %}
        </select>
    </p>
    {% end %}

    <p>
        <label><b>Report SQL</b> {% if errors.get('report_sql') %}<span class="w3-text-red">{{errors['report_sql']}}</span>{% end %}</label>
        <textarea class="w3-input" id="report-textarea" name="report_sql" rows="20">
          {{report_type.get('report_sql', '')}}
        </textarea>
    </p>

    <div class="w3-center w3-padding">
        <a class="w3-left w3-text-blue" href="/admin/report">Cancel</a>
        <input type="submit" class="w3-button w3-blue w3-center" value="{% if report_type %}Update{% else %}Add{% end %} Report"/>
    </div>
</form>

{% end %}
