{% extends 'AdminBundle:User/Layout:show_layout.html.twig' %}

{% form_theme subscriberForm _self %}

{%- set billingType = user.billingSubscription.subscriptionType -%}

{% block show_title %}
    Master User
{% endblock show_title %}

{% block show_content %}
    <h3>
        User information
    </h3>
    <table class="table">
        <tbody>
        <tr>
            <th>First name</th>
            <td>{{ user.firstName }}</td>
        </tr>
        <tr>
            <th>Last name</th>
            <td>{{ user.lastName }}</td>
        </tr>
        <tr>
            <th>
                Expiration Day
            </th>
            <td>{{ user.getExpirationDay|date("m/d/Y") }}</td>
        </tr>
        <tr>
            <th>Number of subscribers</th>
            <td>
                {{- user.billingSubscription.getPlan.subscriberAccounts }} /
                {{ user.billingSubscription.subscriberAccounts -}}
            </td>
        </tr>
        <tr>
            <th>Number of saved feeds allowed</th>
            <td>
                {{- user.billingSubscription.getPlan.savedFeeds }} /
                {{ user.billingSubscription.savedFeeds -}}
            </td>
        </tr>
        <tr>
            <th>Number of alerts allowed</th>
            <td>
                {{- user.billingSubscription.getPlan.alerts }} /
                {{ user.billingSubscription.alerts -}}
            </td>
        </tr>
        <tr>
            <th>Number of newsletters allowed</th>
            <td>
                {{- user.billingSubscription.getPlan.newsletters }} /
                {{ user.billingSubscription.newsletters -}}
            </td>
        </tr>
        <tr>
            <th>Number of ad-hoc searches per day allowed</th>
            <td>
                {{- user.billingSubscription.getPlan.searchesPerDay }} /
                {{ user.billingSubscription.searchesPerDay -}}
            </td>
        </tr>
        <tr>
            <th>
                Billing subscription type
            </th>
            <td>
                {{- billingType.value is constant('ORGANIZATION', billingType) ? 'organization' : 'personal' -}}
            </td>
        </tr>
        </tbody>
    </table>

    {%- if billingType.value is constant('ORGANIZATION', billingType) -%}
    <h3>
        Organization information
    </h3>
    <table class="table">
        <tbody>
            <tr>
                <th>
                    Name
                </th>
                <td>
                    {{- user.billingSubscription.getOrganization.name -}}
                </td>
            </tr>
            <tr>
                <th>
                    Department address
                </th>
                <td>
                    {{- user.billingSubscription.organizationAddress -}}
                </td>
            </tr>
            <tr>
                <th>
                    Department email
                </th>
                <td>
                    {{- user.billingSubscription.organizationEmail -}}
                </td>
            </tr>
            <tr>
                <th>
                    Department phone
                </th>
                <td>
                    {{- user.billingSubscription.organizationPhone -}}
                </td>
            </tr>
        </tbody>
    </table>
    {%- endif -%}

    <h3>
        Subscribers
    </h3>

    <ul>
        {% for subscriber in user.getSubscribers %}
            <li>
                <a href="{{ path('admin_user_subscriber_show', {'id': subscriber.id}) }}">
                    {{ subscriber.firstName }} {{ subscriber.lastName }} ({{ subscriber.email }})
                </a>
            </li>
        {% endfor %}
    </ul>

    {# Add subscribers on MasterUser page Modal #}
    <div class="modal fade" id="subscriber-modal" tabindex="-1" role="dialog" aria-labelledby="add_subscriber">
        {{- form_start(subscriberForm) -}}
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="add_subscriber_header">
                        Subscriber creation
                    </h4>
                </div>
                <div class="modal-body">
                    {{- form_widget(subscriberForm) -}}
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="submit" class="btn btn-primary">Save changes</button>
                </div>
            </div>
        </div>
        {{- form_end(subscriberForm) -}}
    </div>

{% endblock show_content %}

{% block show_buttons %}
    {{- parent() -}}
    <div style="display: inline-block">
        <button type="button" id="subscriber-add" class="btn btn-success">Add Subscriber</button>
    </div>
{% endblock show_buttons %}

{% block javascripts %}
    {{ parent() }}
    <script src="{{ asset('/bundles/admin/js/master_crud.js') }}"></script>
{% endblock javascripts %}

{% block form_errors -%}
    <span class="help-block">
        <ul class="list-unstyled">
            {%- for error in errors -%}
                <li><span class="glyphicon glyphicon-exclamation-sign"></span> {{ error.message }}</li>
            {%- endfor -%}
        </ul>
    </span>
{%- endblock form_errors %}

{%- block hidden_widget -%}
    <div>
        {%- set type = type|default('hidden') -%}
        {{ block('form_widget_simple') }}
    </div>
{%- endblock hidden_widget -%}