{% extends 'layout_default.html.twig' %}

{% block meta_title %}{{ 'Product Promotions'|trans }} - {{ promo.code }}{% endblock %}

{% set active_menu = 'products' %}

{% block breadcrumbs %}
    <ol class="breadcrumb">
        <li class="breadcrumb-item">
            <a href="{{ '/'|alink }}">
                <svg class="icon">
                    <use xlink:href="#home" />
                </svg>
            </a>
        </li>
        <li class="breadcrumb-item">
            <a href="{{ 'product'|alink }}">{{ 'Products'|trans }}</a>
        </li>
        <li class="breadcrumb-item">
            <a href="{{ 'product/promos'|alink }}">{{ 'Product Promotions'|trans }}</a>
        </li>
        <li class="breadcrumb-item active" aria-current="page">{{ promo.code }}</li>
    </ol>
{% endblock %}

{% block content %}
<div class="card">
    <div class="card-body">
        <h3>{{ 'Manage Promotion'|trans }}</h3>
        <form method="post" action="{{ 'api/admin/product/promo_update'|link }}" class="api-form" data-api-redirect="{{ 'product/promos'|alink }}">
            <input type="hidden" name="CSRFToken" value="{{ CSRFToken }}"/>
            <div class="mb-3 row">
                <label class="form-label col-3 col-form-label">{{ 'Promo Code'|trans }}</label>
                <div class="col">
                    <input class="form-control" type="text" name="code" value="{{ promo.code }}" required>
                </div>
            </div>
            <div class="mb-3 row">
                <label class="form-label col-3 col-form-label">{{ 'Discount Type'|trans }}</label>
                <div class="col">
                    <div class="form-check form-check-inline">
                        <input class="form-check-input" id="radioTypeAbsolute" type="radio" name="type" value="absolute"{% if promo.type == 'absolute' %} checked{% endif %}>
                        <label class="form-check-label" for="radioTypeAbsolute">{{ 'Absolute'|trans }}</label>
                    </div>
                    <div class="form-check form-check-inline">
                        <input class="form-check-input" id="radioTypePercentage" type="radio" name="type" value="percentage"{% if promo.type == 'percentage' %} checked{% endif %}>
                        <label class="form-check-label" for="radioTypePercentage">{{ 'Percentage'|trans }}</label>
                    </div>
                    <input class="form-control" type="text" name="value" value="{{ promo.value }}" required>
                </div>
            </div>
            <div class="mb-3 row">
                <label class="form-label col-3 col-form-label">{{ 'Recurring'|trans }}</label>
                <div class="col">
                    <div class="form-check form-check-inline">
                        <input class="form-check-input" id="radioApplyAll" type="radio" name="recurring" value="0"{% if not promo.recurring %} checked{% endif %}>
                        <label class="form-check-label" for="radioApplyAll">{{ 'Apply to first order only'|trans }}</label>
                    </div>
                    <div class="form-check form-check-inline">
                        <input class="form-check-input" id="radioApplyFirst" type="radio" name="recurring" value="1"{% if promo.recurring %} checked{% endif %}>
                        <label class="form-check-label" for="radioApplyFirst">{{ 'Apply to first order and renewals'|trans }}</label>
                    </div>
                </div>
            </div>
            <div class="mb-3 row">
                <label class="form-label col-3 col-form-label">{{ 'Active'|trans }}</label>
                <div class="col">
                    <div class="form-check form-check-inline">
                        <input class="form-check-input" id="radioActiveYes" type="radio" name="active" value="1"{% if promo.active %} checked{% endif %}>
                        <label class="form-check-label" for="radioActiveYes">{{ 'Yes'|trans }}</label>
                    </div>
                    <div class="form-check form-check-inline">
                        <input class="form-check-input" id="radioActiveNo" type="radio" name="active" value="0"{% if not promo.active %} checked{% endif %}>
                        <label class="form-check-label" for="radioActiveNo">{{ 'No'|trans }}</label>
                    </div>
                </div>
            </div>
            <div class="mb-3 row">
                <label class="form-label col-3 col-form-label">{{ 'Free Setup'|trans }}</label>
                <div class="col">
                    <div class="form-check form-check-inline">
                        <input class="form-check-input" id="radioFreeSetupYes" type="radio" name="freesetup" value="1"{% if promo.freesetup %} checked{% endif %}>
                        <label class="form-check-label" for="radioFreeSetupYes">{{ 'Yes'|trans }}</label>
                    </div>
                    <div class="form-check form-check-inline">
                        <input class="form-check-input" id="radioFreeSetupNo" type="radio" name="freesetup" value="0"{% if not promo.freesetup %} checked{% endif %}>
                        <label class="form-check-label" for="radioFreeSetupNo">{{ 'No'|trans }}</label>
                    </div>
                </div>
            </div>

            <h5>{{ 'Promotion Limitations'|trans }}</h5>
            <div class="mb-3 row">
                <label class="form-label col-3 col-form-label">{{ 'Once per Client'|trans }}</label>
                <div class="col">
                    <div class="form-check form-check-inline">
                        <input class="form-check-input" id="radioOncePerClientYes" type="radio" name="once_per_client" value="1"{% if promo.once_per_client %} checked{% endif %}>
                        <label class="form-check-label" for="radioOncePerClientYes">{{ 'Yes'|trans }}</label>
                    </div>
                    <div class="form-check form-check-inline">
                        <input class="form-check-input" id="radioOncePerClientNo" type="radio" name="once_per_client" value="0"{% if not promo.once_per_client %} checked{% endif %}>
                        <label class="form-check-label" for="radioOncePerClientNo">{{ 'No'|trans }}</label>
                    </div>
                </div>
            </div>
            <div class="mb-3 row">
                <label class="form-label col-3 col-form-label">{{ 'Max Uses (Zero for Unlimited)'|trans }}</label>
                <div class="col">
                    <input class="form-control" type="text" name="maxuses" value="{{ promo.maxuses }}" class="dirRight" title="{{ 'Leave blank for unlimited uses'|trans }}" placeholder="0">
                </div>
            </div>
            <div class="mb-3 row">
                <label class="form-label col-3 col-form-label" for="validity">{{ 'Validity Period (Blank for Indefinite)'|trans }}</label>
                <div class="col">
                    <div class="input-icon w-100">
                        <input class="form-control datepicker"
                               id="validity"
                               value="{% if promo.start_at %}{{ promo.start_at|date('Y-m-d') }}{% endif %}{% if promo.end_at %} to {{ promo.end_at|date('Y-m-d') }}{% endif %}"
                               data-name-from="start_at"
                               data-name-to="end_at">
                        <span class="input-icon-addon">
                            <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
                                <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                                <path d="M4 5m0 2a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2z"></path>
                                <path d="M16 3l0 4"></path>
                                <path d="M8 3l0 4"></path>
                                <path d="M4 11l16 0"></path>
                                <path d="M11 15l1 0"></path>
                                <path d="M12 15l0 3"></path>
                            </svg>
                        </span>
                    </div>
                </div>
            </div>
            <div class="mb-3 row">
                <label class="form-label col-3 col-form-label">{{ 'Applicable Products (Select None to Apply to All)'|trans }}</label>
                <div class="col">
                    <input type="hidden" name="products[]" value=""/>
                    <table class="table card-table table-vcenter table-striped text-nowrap">
                        <tbody>
                            {% set products = admin.product_get_pairs %}
                            {% for id,product in products %}
                            <tr><td class="w-1"><input type="checkbox" name="products[]" value="{{ id }}" {% if id in promo.products %} checked{% endif %} /></td><td>{{ product }}</td></tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="mb-3 row">
                <label class="form-label col-3 col-form-label">{{ 'Applicable Periods (Select None to Apply to All)'|trans }}</label>
                <div class="col">
                    <input type="hidden" name="periods[]" value=""/>
                    <table class="table card-table table-vcenter table-striped text-nowrap">
                        <tbody>
                            {% set periods = guest.system_periods %}
                            {% for id, period in periods %}
                            <tr><td class="w-1"><input type="checkbox" name="periods[]" value="{{ id }}" {% if id in promo.periods %} checked{% endif %} /></td><td>{{ period }}</td></tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="mb-3 row">
                <label class="form-label col-3 col-form-label">{{ 'Applicable Client Groups (Select None to Apply to All)'|trans }}</label>
                <div class="col">
                    <input type="hidden" name="client_groups[]" value="{{ id }}"/>
                    <table class="table card-table table-vcenter table-striped text-nowrap">
                        <tbody>
                            {% set client_groups = admin.client_group_get_pairs %}
                            {% for id, client_group in client_groups %}
                            <tr><td class="w-1"><input type="checkbox" name="client_groups[]" value="{{ id }}" {% if id in promo.client_groups %} checked{% endif %} /></td><td>{{ client_group }}</td></tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
            <input type="hidden" name="id" value="{{ promo.id }}">
            <input type="submit" value="{{ 'Update'|trans }}" class="btn btn-primary w-100">
        </form>
    </div>
</div>
{% endblock %}
