{% extends '_layouts/cp' %}
{% import '_includes/forms' as forms %}
{% import 'verbb-base/_macros' as macros %}

{% do view.registerAssetBundle('verbb\\formie\\web\\assets\\cp\\CpAsset') -%}

{% set crumbs = [
    { label: craft.formie.getPluginName() | t('formie'), url: url('formie') },
    { label: 'Sent Notifications' | t('formie'), url: url('formie/sent-notifications') },
] %}

{% set form = sentNotification.getForm() %}

{% if sentNotification.canDelete(currentUser) %}
    {% set fullPageForm = true %}
{% endif %}

{% set bodyClass = 'fui-body' %}
{% set selectedSubnavItem = 'sentNotifications' %}

{% hook 'formie.cp.sentNotifications.edit' %}

{% block actionButton %}

{% if sentNotification.canDelete(currentUser) %}
    <input type="hidden" name="sentNotificationId" value="{{ sentNotification.id }}">

    <a class="btn formsubmit" data-action="formie/sent-notifications/delete" data-confirm="{{ 'Are you sure you want to delete this sent notification?' | t('formie') }}" data-redirect="{{ 'formie/sent-notifications' | hash }}">{{ 'Delete' | t('app') }}</a>
{% endif %}

{% endblock %}

{% block content %}

{% include 'formie/sent-notifications/_includes/preview' %}

{% hook 'formie.cp.sentNotifications.edit.content' %}

{% endblock %}

{% block details %}

<div id="settings" class="meta">
    <div class="field">
        <div class="heading">
            <label class="">{{ 'Status' | t('formie') }}</label>
        </div>

        <div class="input ltr">
            <div id="status-value" class="value">
                {% if sentNotification.status == 'success' %}
                    <span class="status on"></span>{{ 'Success' | t('formie') }}
                {% else %}
                    <span class="status off"></span>{{ 'Failed' | t('formie') }} <span class="info">{{ sentNotification.message }}</span>
                {% endif %}
            </div>
        </div>
    </div>

    {% if sentNotification.canResend(currentUser) %}
        <div class="field">
            <div class="heading">
                <label class="">{{ 'Resend' | t('formie') }}</label>
            </div>

            <div class="input ltr">
                <a class="js-fui-notification-modal-resend-btn btn small" data-id="{{ sentNotification.id }}">{{ 'Resend' | t('formie') }}</a>
            </div>
        </div>
    {% endif %}

    <div class="field">
        <div class="heading">
            <label class="">{{ 'Form Name' | t('formie') }}</label>
        </div>

        <div class="input ltr">
            {% if sentNotification.form %}
                <a href="{{ sentNotification.form.getCpEditUrl() }}">{{ sentNotification.form }}</a>
            {% else %}
                {{ 'Deleted' | t('formie') }}
            {% endif %}
        </div>
    </div>

    <div class="field">
        <div class="heading">
            <label class="">{{ 'Submission' | t('formie') }}</label>
        </div>

        <div class="input ltr">
            {% if sentNotification.submission %}
                <a href="{{ sentNotification.submission.getCpEditUrl() }}">{{ sentNotification.submission }}</a>
            {% else %}
                {{ 'Deleted' | t('formie') }}
            {% endif %}
        </div>
    </div>

    <div class="field">
        <div class="heading">
            <label class="">{{ 'Notification' | t('formie') }}</label>
        </div>

        <div class="input ltr">
            {% if sentNotification.notification %}
                {{ sentNotification.notification }}
            {% else %}
                {{ 'Deleted' | t('formie') }}
            {% endif %}
        </div>
    </div>
</div>

<div id="meta-details" class="meta read-only">
    {% block meta %}
        <div class="data">
            <h5 class="heading">{{ 'Date Sent' | t('formie') }}</h5>
            <div id="date-created-value" class="value">{{ sentNotification.dateCreated | datetime('short') }}</div>
        </div>

        {% for key, item in sentNotification.info %}
            <div class="data">
                <h5 class="heading">{{ key | camel2words }}</h5>
                <div class="value">{{ item }}</div>
            </div>
        {% endfor %}
    {% endblock %}
</div>

{% hook 'formie.cp.sentNotifications.edit.details' %}

{% endblock %}
