{% extends 'layouts/admin.twig' %}

{% block content %}

    <ul class="breadcrumbs el">
        <li><a href="/admin/">Admin</a> /</li>
        <li class="end">Subscription</li>
    </ul>

    <h1>{{ title }}</h1>

    <ul class="tabnav el">
        <li class="{{ selected_tab == 'manage' ? 'selected' : '' }}">
            <a href="{{ route('admin-subscriptions') }}">All</a>
        </li>
        <li class="{{ selected_tab == 'edit' ? 'selected' : '' }}">
            <a href="">Edit</a>
        </li>
    </ul>


    {% include 'admin/messages.twig' %}

    {% set form_errors = messages.errors %}

    <form action="" method="POST" class="style">
        <fieldset class="show">
            <h1><a class="show el">Configured values<i class="fa fa-caret-right"></i></a></h1>

            <div class="row">
                <label>Member</label>
                <div class="defaultValue">
                    <a href="{{ route('admin-manage-member', { member_id: subscription.member.id }) }}">{{ subscription.member.email }}</a>
                </div>
            </div>

            {{ form_field({
                'type': 'text',
                'name': 'interval_multiplier',
                'label': 'Interval Multiplier',
                'value': subscription.interval_multiplier,
                'errors': form_errors,
            }) }}

            {{ form_field({
                'type': 'select',
                'name': 'interval',
                'label': 'Interval',
                'value': subscription.interval,
                'values': allowed_intervals,
                'errors': form_errors,
            }) }}

            {{ form_field({
                'type': 'select',
                'name': 'status',
                'label': 'Status',
                'value': subscription.status,
                'values': allowed_statuses,
                'errors': form_errors,
            }) }}

            {{ form_field({
                'type': 'number',
                'name': 'max_number_of_issues',
                'label': 'Max number of issues',
                'value': subscription.max_number_of_issues,
                'notes': 'Calculated effective value: ' ~ subscription.getMaxNumberOfIssues(),
                'errors': form_errors,
            }) }}

            {{ form_field({
                'type': 'text',
                'name': 'expiry_date',
                'label': 'Expiry date',
                'value': subscription.expiry_date,
                'notes': '(based on the related assessment form)',
                'class': 'datetim',
                'errors': form_errors,
                'readonly': false,
            }) }}

            {{ form_field({
                'type': 'checkbox',
                'name': 'can_be_paused',
                'id': 'can_be_paused',
                'label': 'Can be paused',
                'value': subscription.can_be_paused,
                'notes': 'Calculated effective value: ' ~ subscription.getCanBePausedString(),
                'field_value': 1,
                'errors': form_errors,
            }) }}

            {{ form_field({
                'type': 'text',
                'name': 'next_issue_date',
                'label': 'Next issue date',
                'value': subscription.next_issue_date,
                'notes': 'Calculated effective next-issue date: ' ~ subscription.getNextIssueDate(),
                'class': 'datetim',
                'errors': form_errors,
            }) }}

            {{ form_field({
                'type': 'text',
                'name': 'price_per_issue',
                'label': 'Price per issue',
                'value': subscription.price_per_issue,
                'notes': 'Calculated effective price: ' ~ subscription.getPricePerIssue(),
                'errors': form_errors,
            }) }}


            <div class="row">
                <button type="submit" name="button_pressed" value="save" class="btn">
                    Save
                </button>
            </div>

        </fieldset>

        <fieldset class="show">
            <h1><a class="show el">Manage items <i class="fa fa-caret-right"></i></a></h1>

            {{ form_field({
                'type': 'select',
                'name': 'item_to_add',
                'label': 'Items',
                'values': allowed_items,
            }) }}

            <button type="submit" name="button_pressed" value="add_item"  class="btn">
                Add selected item
            </button>

            {% include 'admin/subscription__manage_items.twig' with {
                'items': subscription.items,
                'delete_route_name': 'admin-subscriptions-items-delete',
            } %}

        </fieldset>


        <fieldset class="show">
            <h1><a class="show el">Test actions<i class="fa fa-caret-right"></i></a></h1>

            <div class="row">
                <a href="{{ route('admin-subscriptions-generate-order', { subscription_id: subscription.id }) }}"
                    class="btn"
                    target="_blank"
                >
                    Generate Order (no payment)
                </a>
            </div>

            <div class="row">
                <a href="{{ route('admin-subscriptions-generate-order', { subscription_id: subscription.id, attempt_token_payment: 'y' }) }}"
                    class="btn"
                    target="_blank"
                >
                    Generate Order (attempt payment)
                </a>
            </div>

            <div class="row">
                <a href="{{ route('admin-subscriptions-generate-order', { subscription_id: subscription.id, ignore_checks: 'y' }) }}"
                    class="btn"
                    target="_blank"
                >
                    Generate Order (no checks + no payment)
                </a>
            </div>

            <div class="row">
                <a href="{{ route('admin-subscriptions-generate-order', { subscription_id: subscription.id, attempt_token_payment: 'y', ignore_checks: 'y' }) }}"
                    class="btn"
                    target="_blank"
                >
                    Generate Order (no checks + attempt payment)
                </a>
            </div>
        </fieldset>

    </form>



{% endblock %}
