{% extends "base-install.twig" %}
{% import "forms.twig" as forms %}

{% block stepContent %}
    <div class="row">
        <div class="col-md-12">
            {% set themeName = theme.getThemeConfig("app_name") %}
            <ul class="nav nav-tabs" role="tablist">
                <li class="nav-item"><a class="nav-link active" href="#new" role="tab" data-toggle="tab"><span>{% trans "New" %}</span></a></li>
                <li class="nav-item"><a class="nav-link" href="#existing" role="tab" data-toggle="tab"><span>{% trans "Existing" %}</span></a></li>
            </ul>
            <form action="{{ url_for("install", {step: 3}) }}" class="form-horizontal" method="post">
                <div class="tab-content">
                    <div class="tab-pane active" id="new">
                        {% set message %}{% trans %}{{ themeName }} needs to set-up a connection to your MySQL database.{% endtrans %}{% endset %}
                        {{ forms.message(message) }}

                        {% set message %}{% trans "If you have not yet created an empty database and database user for Xibo to use, and know the user name / password of a MySQL administrator stay on this tab, otherwise click \"Use Existing\"." %}{% endset %}
                        {{ forms.message(message) }}

                        {% set title %}{% trans "Create a new database" %}{% endset %}
                        {% set helpText %}{% trans "Select to create a new database" %}{% endset %}
                        {{ forms.radio("db_create", "db_create1", title, session['db_create'], helpText, "", "", 1) }}

                        {% set title %}{% trans "Host" %}{% endset %}
                        {% set helpText %}{% trans "Please enter the hostname for the MySQL server. This is usually localhost." %}{% endset %}
                        {{ forms.input("host",  title, session['new_db_host'], helpText) }}

                        {% set title %}{% trans "Admin Username" %}{% endset %}
                        {% set helpText %}{% trans "Please enter the user name of an account that has administrator privileges on the MySQL server." %}{% endset %}
                        {{ forms.input("admin_username",  title, session['db_admin_user'], helpText) }}

                        {% set title %}{% trans "Admin Password" %}{% endset %}
                        {% set helpText %}{% trans "Please enter password for the Admin account." %}{% endset %}
                        {{ forms.password("admin_password",  title, session['db_admin_pass'], helpText) }}

                        {% set title %}{% trans "Database Name" %}{% endset %}
                        {% set helpText %}{% trans "Please enter the name of the database that should be created." %}{% endset %}
                        {{ forms.input("db_name",  title, session['new_db_name'], helpText) }}

                        {% set title %}{% trans "Database Username" %}{% endset %}
                        {% set helpText %}{% trans "Please enter the name of the database user that should be created." %}{% endset %}
                        {{ forms.input("db_username",  title, session['new_db_user'], helpText) }}

                        {% set title %}{% trans "Database Password" %}{% endset %}
                        {% set helpText %}{% trans "Please enter a password for this user." %}{% endset %}
                        {{ forms.password("db_password",  title, session['new_db_pass'], helpText) }}

                        {% set title %}{% trans "CA File" %}{% endset %}
                        {% set helpText %}{% trans "To connect to a MySQL server over SSL, enter the path to the CA file." %}{% endset %}
                        {{ forms.input("db_ssl_ca",  title, session['new_db_ssl_ca'], helpText) }}

                        {% set title %}{% trans "Verify CA Identity?" %}{% endset %}
                        {% set helpText %}{% trans "Turn this off for self-signed certificates." %}{% endset %}
                        {{ forms.checkbox("db_ssl_verify", title, session['new_db_ssl_verify'], helpText) }}
                    </div>
                    <div class="tab-pane" id="existing">
                        {% set title %}{% trans "Use an existing database" %}{% endset %}
                        {% set helpText %}{% trans "Select to use an existing database. Please note that when you use an existing database it must be empty of all other contents." %}{% endset %}
                        {{ forms.radio("db_create", "db_create2", title, session['db_create'], helpText, "", "", 2) }}

                        {% set title %}{% trans "Host" %}{% endset %}
                        {% set helpText %}{% trans "Please enter the hostname for the MySQL server. This is usually localhost." %}{% endset %}
                        {{ forms.input("existing_host",  title, session['existing_db_host'], helpText) }}

                        {% set title %}{% trans "Database Name" %}{% endset %}
                        {% set helpText %}{% trans "Please enter the name of the database that should be used." %}{% endset %}
                        {{ forms.input("existing_db_name",  title, session['existing_db_name'], helpText) }}

                        {% set title %}{% trans "Database Username" %}{% endset %}
                        {% set helpText %}{% trans "Please enter the name of the database user that should be used." %}{% endset %}
                        {{ forms.input("existing_db_username",  title, session['existing_db_user'], helpText) }}

                        {% set title %}{% trans "Database Password" %}{% endset %}
                        {% set helpText %}{% trans "Please enter a password for this user." %}{% endset %}
                        {{ forms.password("existing_db_password",  title, session['existing_db_pass'], helpText) }}

                        {% set title %}{% trans "CA File" %}{% endset %}
                        {% set helpText %}{% trans "To connect to a MySQL server over SSL, enter the path to the CA file." %}{% endset %}
                        {{ forms.input("existing_db_ssl_ca",  title, session['existing_db_ssl_ca'], helpText) }}

                        {% set title %}{% trans "Verify CA Identity?" %}{% endset %}
                        {% set helpText %}{% trans "Turn this off for self-signed certificates." %}{% endset %}
                        {{ forms.checkbox("existing_db_ssl_verify", title, session['existing_db_ssl_verify'], helpText) }}
                    </div>
                </div>

                {% set title %}{% trans "Next" %}{% endset %}
                {{ forms.button(title, "submit") }}
            </form>
        </div>
    </div>
{% endblock %}