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

{% block content %}
    <h1 class="page-header">
        {{ (is_new ? 'marketing.abandoned_cart.rule.new_title' : 'marketing.abandoned_cart.rule.edit_title')|trans }}
    </h1>

    {{ form_start(form, {attr: {novalidate: 'novalidate'}}) }}
        <div class="panel panel-default">
            <div class="panel-heading">
                <a class="btn btn-danger btn-rounded" href="{{ path('admin_marketing_abandoned_cart') }}">
                    {{ 'marketing.common.back'|trans }}
                </a>
                <button type="submit" class="btn btn-primary btn-rounded">
                    {{ 'marketing.common.save'|trans }}
                </button>
            </div>
        </div>

        <div class="panel panel-info">
            <div class="panel-heading">{{ 'marketing.abandoned_cart.rule.schedule_title'|trans }}</div>
            <div class="panel-body">
                {{ form_row(form.name) }}
                {{ form_row(form.enabled) }}
                {{ form_row(form.position) }}
                {{ form_row(form.delayHours) }}
                {{ form_row(form.validityDays) }}
            </div>
        </div>

        <div class="panel panel-info">
            <div class="panel-heading">{{ 'marketing.abandoned_cart.rule.conditions_title'|trans }}</div>
            <div class="panel-body">
                {{ form_row(form.minSubtotalTTC) }}
                {{ form_row(form.maxSubtotalTTC) }}
                {{ form_row(form.countryCodes) }}
                {{ form_row(form.customerType) }}
            </div>
        </div>

        <div class="panel panel-info">
            <div class="panel-heading">{{ 'marketing.abandoned_cart.rule.coupon_title'|trans }}</div>
            <div
                class="panel-body"
                data-abandoned-cart-discount
            >
                <div class="alert alert-info">{{ 'marketing.abandoned_cart.rule.coupon_help'|trans }}</div>
                {{ form_row(form.discountType, {attr: {'data-discount-type': true}}) }}
                {{ form_row(form.priceGroup) }}
                {{ form_row(form.couponOnlyWithoutExistingDiscount) }}
                <div
                    data-discount-field="{{ constant('CpCreation\\VitiCore\\Marketing\\Model\\AbandonedCartRule::DISCOUNT_FIXED') }}"
                    {% if rule.discountType != constant('CpCreation\\VitiCore\\Marketing\\Model\\AbandonedCartRule::DISCOUNT_FIXED') %}hidden{% endif %}
                >
                    {{ form_row(form.discountAmountTTC) }}
                </div>
                <div
                    data-discount-field="{{ constant('CpCreation\\VitiCore\\Marketing\\Model\\AbandonedCartRule::DISCOUNT_PERCENT') }}"
                    {% if rule.discountType != constant('CpCreation\\VitiCore\\Marketing\\Model\\AbandonedCartRule::DISCOUNT_PERCENT') %}hidden{% endif %}
                >
                    {{ form_row(form.discountPercent) }}
                </div>
            </div>
        </div>

        <div class="panel panel-default">
            <div class="panel-body text-right">
                <button type="submit" class="btn btn-primary btn-rounded">
                    {{ 'marketing.common.save'|trans }}
                </button>
            </div>
        </div>
    {{ form_end(form) }}
{% endblock %}

{% block javascripts %}
    {{ parent() }}
    <script src="{{ asset('bundles/cpcreationviticore/js/admin/abandoned-cart-rule.js?v20260723') }}"></script>
{% endblock %}
