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

{% block content %}
    <ul class="breadcrumbs el">
        <li><a href="/admin/">Admin</a> /</li>
        <li><a href="{{ route('admin-subscriptions') }}">Subscriptions</a> /</li>
        <li><a href="{{ route('admin-subscription-logs') }}">Logs</a> /</li>
        <li class="end">Subscription #{{ subscription.id }}</li>
    </ul>

    <div class="content-card">
        <h1>{{ title }}</h1>

        <div class="page-actions" style="margin-bottom: 20px;">
            <a href="{{ route('admin-subscriptions') }}" class="BUTTON">
                <i class="fa fa-arrow-left"></i> Back to Subscriptions
            </a>
            <a href="{{ route('admin-subscription-logs') }}" class="BUTTON">
                <i class="fa fa-arrow-left"></i> Back to All Logs
            </a>
            <a href="{{ route('admin-subscriptions-edit', subscription.id) }}" class="BUTTON">
                <i class="fa fa-edit"></i> Edit Subscription
            </a>
        </div>

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

        <!-- Subscription Overview -->
        <form class="style">
            <fieldset class="show">
                <h1><a class="show el">Subscription Overview <i class="fa fa-caret-down"></i></a></h1>
                <div class="row">
                    <label>Subscription ID:</label>
                    <span>#{{ subscription.id }}</span>
                </div>
                <div class="row">
                    <label>Status:</label>
                    <span class="badge badge-{{ subscription.status }}">{{ subscription.status|title }}</span>
                </div>
                <div class="row">
                    <label>Member:</label>
                    <span>{{ subscription.member.full_name }} ({{ subscription.member.email }}) [ID #{{ subscription.member.id }}]</span>
                </div>
                <div class="row">
                    <label>Created:</label>
                    <span>{{ subscription.created_at|date('d/m/Y H:i') }}</span>
                </div>
                <div class="row">
                    <label>Interval:</label>
                    <span>Billed {% if subscription.interval_multiplier == 1 %}{% if subscription.interval == 'weeks' %}weekly{% elseif subscription.interval == 'months' %}monthly{% elseif subscription.interval == 'years' %}yearly{% elseif subscription.interval == 'days' %}daily{% else %}every {{ subscription.interval|trim('s') }}{% endif %}{% elseif subscription.interval_multiplier == 2 and subscription.interval == 'weeks' %}bi-weekly{% else %}every {{ subscription.interval_multiplier }} {{ subscription.interval }}{% endif %}</span>
                </div>
                {# <div class="row">
                    <label>Price per Issue:</label>
                    <span>£{{ subscription.price_per_issue }}</span>
                </div> #}
                <div class="row">
                    <label>Next Issue:</label>
                    <span>{{ subscription.next_issue_date|date('d/m/Y') }}</span>
                </div>
                <div class="row">
                    <label>Total Orders:</label>
                    <span>{{ subscription.orders|length }}</span>
                </div>
            </fieldset>

            <fieldset class="show">
                <h1><a class="show el">Subscription Items <i class="fa fa-caret-down"></i></a></h1>
                {% if subscription.items|length > 0 %}
                <div class="subscription-items">
                    <table>
                        <thead>
                            <tr>
                                <th>Item</th>
                                <th>Quantity</th>
                                <th>Price</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for item in subscription.items %}
                                <tr>
                                    <td>{{ item.getDisplayName() }}</td>
                                    <td>{{ item.quantity }}</td>
                                    <td>£{{ (item.shop_item_size ? item.shop_item_size.price : item.shop_item.price) | number_format(2) }}</td>
                                </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
                {% endif %}
            </fieldset>

            <hr>

            <fieldset class="show">
                <h1><a class="show el">Subscription Orders <i class="fa fa-caret-down"></i></a></h1>
                <table class="manage-items">
                    <thead>
                        <tr>
                            <th>Order ID</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th>Total</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for order in subscription.orders %}
                            <tr>
                                <td>{{ order.id }}</td>
                                <td>{{ order.date | date('d/m/Y H:i:s')}}</td>
                                <td>{{ order.getOrderStatusTitle() | title }}</td>
                                <td>£{{ order.cost_total | number_format(2) }}</td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
            </fieldset>

            <hr>

            {% include 'admin/partials/subscription_logs.twig' with {
                'logs': logs,
            } %}

        </form>
    </div>





{% endblock %}
{% block head %}
<link rel="stylesheet" href="/plugins/mtc_pharmacy_subscriptions/admin/css/style.css">
{% endblock %}