{# app/modules/loyalty/templates/loyalty/store/settings.html #}
{% extends "store/base.html" %}
{% from 'shared/macros/headers.html' import page_header_flex %}
{% from 'shared/macros/alerts.html' import loading_state, error_state %}
{% from 'shared/macros/modals.html' import confirm_modal %}

{% block title %}{{ _('loyalty.store.settings.title') }}{% endblock %}

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

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

{% block content %}
<!-- Page Header -->
{% call page_header_flex(title=_('loyalty.store.settings.page_title'), subtitle=_('loyalty.store.settings.subtitle')) %}
    <div class="flex items-center gap-3">
        <a href="/store/{{ store_code }}/loyalty/program"
           class="flex items-center px-4 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 dark:bg-gray-800 dark:text-gray-300 dark:border-gray-600 dark:hover:bg-gray-700">
            <span x-html="$icon('arrow-left', 'w-4 h-4 mr-2')"></span>
            {{ _('loyalty.store.settings.back_to_program') }}
        </a>
    </div>
{% endcall %}

{{ loading_state(_('loyalty.store.settings.loading')) }}

{{ error_state(_('loyalty.store.settings.error_loading')) }}

<!-- Access Denied (non-owner) -->
<div x-show="!loading && !isOwner" class="mb-6 px-4 py-5 bg-yellow-50 border border-yellow-200 rounded-lg dark:bg-yellow-900/20 dark:border-yellow-800">
    <div class="flex items-start">
        <span x-html="$icon('shield', 'w-6 h-6 text-yellow-500 mr-3 flex-shrink-0')"></span>
        <div>
            <h3 class="text-sm font-semibold text-yellow-800 dark:text-yellow-200">{{ _('loyalty.store.settings.access_restricted') }}</h3>
            <p class="mt-1 text-sm text-yellow-700 dark:text-yellow-300">{{ _('loyalty.store.settings.access_restricted_desc') }}</p>
        </div>
    </div>
</div>

<!-- Settings Form -->
<div x-show="!loading && isOwner">
    <form @submit.prevent="saveSettings">
        {% set show_delete = true %}
        {% set show_status = true %}
        {% set cancel_url = '/store/' ~ store_code ~ '/loyalty/program' %}
        {% include "loyalty/shared/program-form.html" %}
    </form>
</div>

<!-- Delete Confirmation Modal -->
{{ confirm_modal(
    'deleteProgramModal',
    _('loyalty.store.settings.delete_program_title'),
    _('loyalty.store.settings.delete_program_desc'),
    'deleteProgram()',
    'showDeleteModal',
    _('loyalty.store.settings.delete_program_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='store/js/loyalty-settings.js') }}"></script>
{% endblock %}
