{# app/modules/loyalty/templates/loyalty/admin/program-edit.html #}
{% extends "admin/base.html" %}
{% from 'shared/macros/headers.html' import detail_page_header %}
{% from 'shared/macros/alerts.html' import loading_state, error_state %}
{% from 'shared/macros/modals.html' import confirm_modal %}

{% block title %}{{ _('loyalty.admin.program_edit.title') }}{% endblock %}

{% block i18n_modules %}['loyalty']{% endblock %}

{% block alpine_data %}adminLoyaltyProgramEdit(){% endblock %}

{% block content %}
{% call detail_page_header("isNewProgram ? 'Create Program: ' + (merchant?.name || '') : 'Edit Program: ' + (merchant?.name || '')", '/admin/loyalty/merchants/' ~ merchant_id, subtitle_show='merchant') %}
    <span x-text="isNewProgram ? '{{ _('loyalty.admin.program_edit.create_subtitle')|replace("'", "\\'") }}' : '{{ _('loyalty.admin.program_edit.edit_subtitle')|replace("'", "\\'") }}'"></span>
{% endcall %}

{{ loading_state(_('loyalty.admin.program_edit.loading')) }}
{{ error_state(_('loyalty.admin.program_edit.error_loading')) }}

<div x-show="!loading">
    <form @submit.prevent="saveSettings">
        {% set show_delete = true %}
        {% set show_status = true %}
        {% set cancel_url = '/admin/loyalty/merchants/' ~ merchant_id %}
        {% include "loyalty/shared/program-form.html" %}
    </form>
</div>

<!-- Delete Confirmation Modal -->
{{ confirm_modal(
    'deleteProgramModal',
    _('loyalty.admin.program_edit.delete_title'),
    _('loyalty.admin.program_edit.delete_message'),
    'deleteProgram()',
    'showDeleteModal',
    _('loyalty.admin.program_edit.delete_confirm'),
    _('loyalty.common.cancel'),
    'danger'
) }}
{% endblock %}

{% block extra_scripts %}
<script defer src="{{ url_for('loyalty_static', path='shared/js/loyalty-program-form.js') }}"></script>
<script defer src="{{ url_for('loyalty_static', path='admin/js/loyalty-program-edit.js') }}"></script>
{% endblock %}
