{% extends '@CpCreationVitiCore/admin/base.html.twig' %}

{% block title %}{{ 'commerce_catalog.admin.page_title'|trans }} - {{ parent() }}{% endblock %}

{% block content %}
    <h1 class="page-header">{{ 'commerce_catalog.admin.heading'|trans }}</h1>

    {{ form_start(form, {
        action: path('admin_commerce_configuration'),
        attr: { novalidate: 'novalidate' }
    }) }}
        <div class="panel panel-default">
            <div class="panel-heading">
                <a href="{{ path('admin_homepage') }}" class="btn btn-danger btn-rounded">
                    {{ 'commerce_catalog.admin.cancel'|trans }}
                </a>
                <button type="submit" class="btn btn-primary form-submit btn-rounded">
                    {{ 'commerce_catalog.admin.save'|trans }}
                </button>
                <div class="clearfix"></div>
            </div>
        </div>

        {% if not form.vars.valid %}
            <div class="alert alert-danger" role="alert">
                <strong>{{ 'commerce_catalog.admin.errors_heading'|trans }}</strong>
                {{ form_errors(form) }}
            </div>
        {% endif %}

        <div class="row">
            <div class="col-md-6">
                <div class="panel panel-info">
                    <div class="panel-heading">{{ 'commerce_catalog.admin.settings'|trans }}</div>
                    <div class="panel-body">
                        {{ form_row(form.enabled) }}
                        {{ form_row(form.monitoringEnabled) }}
                        {{ form_row(form.hubUrl) }}
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <div class="panel panel-info">
                    <div class="panel-heading">{{ 'commerce_catalog.admin.technical_information'|trans }}</div>
                    <div class="panel-body">
                        <dl class="dl-horizontal">
                            <dt>{{ 'commerce_catalog.admin.instance_id'|trans }}</dt>
                            <dd><code>{{ item.instanceId.toString }}</code></dd>

                            <dt>{{ 'commerce_catalog.admin.status_label'|trans }}</dt>
                            <dd>{{ ('commerce_catalog.admin.status.' ~ item.status.value)|trans }}</dd>

                            <dt>{{ 'commerce_catalog.admin.source_id'|trans }}</dt>
                            <dd>{{ item.sourceId ?: 'commerce_catalog.admin.not_available'|trans }}</dd>

                            <dt>{{ 'commerce_catalog.admin.webhook_url'|trans }}</dt>
                            <dd class="text-break">{{ item.webhookUrl ?: 'commerce_catalog.admin.not_available'|trans }}</dd>

                            <dt>{{ 'commerce_catalog.admin.token_expires_at'|trans }}</dt>
                            <dd>
                                {{ item.enrollmentTokenExpiresAt
                                    ? item.enrollmentTokenExpiresAt|format_datetime('medium', 'short')
                                    : 'commerce_catalog.admin.not_available'|trans }}
                            </dd>

                            <dt>{{ 'commerce_catalog.admin.enrolled_at'|trans }}</dt>
                            <dd>
                                {{ item.enrolledAt
                                    ? item.enrolledAt|format_datetime('medium', 'short')
                                    : 'commerce_catalog.admin.not_available'|trans }}
                            </dd>
                        </dl>

                        {% if item.status.value == 'error' %}
                            <div class="alert alert-warning" role="status">
                                {{ 'commerce_catalog.admin.error_notice'|trans }}
                            </div>
                        {% endif %}

                        <p class="help-block">{{ 'commerce_catalog.admin.secrets_notice'|trans }}</p>
                        {% if item.hubConnectionEnabled %}
                            <p class="help-block">{{ 'commerce_catalog.admin.reconnect_help'|trans }}</p>
                            <button type="submit" name="reconnect" value="1" class="btn btn-warning btn-rounded">
                                {{ 'commerce_catalog.admin.reconnect'|trans }}
                            </button>
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>

        {{ form_rest(form) }}

        <div class="panel panel-default">
            <div class="panel-heading">
                <a href="{{ path('admin_homepage') }}" class="btn btn-danger btn-rounded">
                    {{ 'commerce_catalog.admin.cancel'|trans }}
                </a>
                <button type="submit" class="btn btn-primary form-submit btn-rounded">
                    {{ 'commerce_catalog.admin.save'|trans }}
                </button>
                <div class="clearfix"></div>
            </div>
        </div>
    {{ form_end(form) }}
{% endblock %}
