{% import 'common/thumbnail.html.twig' as thumbnail %}
{% set displayName = order.getUser().getDisplayName() %}

<div class="order-header">
    <div class="alert">
        {{ 'Il se peux que vous ne voyez pas tous les elements. Vous ne verrez que les  elements correspondants aux collections sur lesquelles vous gerez les commandes' | trans }}
    </div>
    <button class="order_launcher btn rightside"><i class="fa fa-chevron-left"
                                                    aria-hidden="true"></i>{{ 'Retour aux commandes' | trans }}</button>
</div>

<div style="display:none;position:relative;" id="basket-window" >
    <form method="POST" action="{{ path('prod_baskets') }}">
        <label>{{ 'Nom du nouveau panier' | trans }}</label>
        <input name="name" class="input-block-level" value="" type="text"/>

        <label>{{ 'paniers::description du nouveau panier' | trans }}</label>
        <textarea name="description" class="input-block-level" ></textarea>

        <label for="new_basket_add_sel" class="checkbox">
            <input type="checkbox" name="lst" value="" id="new_basket_add_sel"/>
            {{ 'Ajouter ma selection courrante' | trans }}
        </label>
    </form>
</div>

<div style="display:none;position:relative;" id="validation-window" >
    <div class="box">
        <div class="validation-content" style="float:left; width:100%;margin-top:10px;">
        </div>
    </div>
</div>

<div id="order_manager" style="margin-top: 15px">
    {% set success = app['request'].query.get('success') %}
    {% set action = app['request'].query.get('action') %}
    {% set message = app['request'].query.get('message') %}

    {% if  success == '1' %}
        <div class="alert alert-success">
            <button type="button" class="close" data-dismiss="alert">×</button>
            {% if action == 'send' %}
                {{ 'Order has been sent' | trans }}
            {% elseif action == 'deny' %}
                {{ 'Order has been denied' | trans }}
            {% elseif action == 'basket' %}
                {{ message }}
            {% endif %}
        </div>
    {% elseif   success == '0' %}
        <div class="alert alert-error">
            <button type="button" class="close" data-dismiss="alert">×</button>
            {{ 'An error occured, please retry or contact an admin if problem persists' | trans }}
        </div>
    {% endif %}


    <div class="well no-margin">
        <div id="userInfoPreview">
            <div class="userInfoName">
                <span>{{ order.getUser().getDisplayName() }}</span>
            </div>
            <span class="userdetail"><strong>{{ 'order-manager::order-item: company' | trans }}</strong> {{ order.getUser().getCompany() }}</span>
            <span class="userdetail"><strong>{{ 'order-manager::order-item: tel' | trans }}</strong> {{ order.getUser().getPhone() }}</span>
            <span class="userdetail"><strong>{{ 'order-manager::order-item: address' | trans }}</strong> {{ order.getUser().getAddress() }}</span>
            <span class="userdetail"><strong>{{ 'order-manager::order-item: country' | trans }}</strong> {{ order.getUser().getCountry() }}</span>
        </div>

        <table class="table no-border">
            <tr>
                <td>
                    <span class="text_block">{{ 'order-manager::order-list: order-id' | trans }}</span>
                    <span class="text_block_bold">{{ order.getId() }}</span>
                </td>
                <td width="20%">
                    <span class="text_block">{{ 'Date de demande' | trans }}</span>
                    <span class="text_block_bold">{{ order.getCreatedOn()|date('d/m/Y') }}</span>
                </td>
                <td width="20%">
                    <span class="text_block">{{ 'Deadline' | trans }}</span>
                    <span class="text_block_bold">{{ order.getDeadline()|date('d/m/Y') }}</span>
                </td>
                <td width="20%">
                    <span class="text_block">{{ 'order-manager::order-list: treated-documents' | trans }}</span>
                    <span class="text_block_bold">{{ order.getTotalTreatedItems() }}/{{ order.getTotal() }}</span>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <span class="text_block">{{ displayName }} (<a
                                style="font-size: 12px;color: #4990E2;" href="#" id="email-btn">{{ order.getUser().getEmail() }}</a>)
                        <span class="fa-stack infoTips" id="userInfo">
                            <i class="fa fa-circle fa-stack-2x" aria-hidden="true" style="color:#737373"></i>
                            <i class="fa fa-info fa-stack-1x" style="color:#FFF" aria-hidden="true"></i>
                        </span>
                    </span>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <span class="text_block">{{ 'commande::utilisation prevue' | trans }}</span>
                    <h4 class="minimize">{{ order.getOrderUsage() }}</h4>
                </td>
            </tr>
        </table>
        <button class="btn validate outline" disabled><i class="fa fa-check-circle-o"
                                                         aria-hidden="true"></i>{{ 'order-manager::order-item: validate' |trans }}
        </button>
        <div class="order-list-container">
            <div class="order_list" style="width:40%;float:left">
                <div class="top-bar">
                    <form action="">
                        <input type="checkbox" name="select-all" value="all"/><span>{{ 'order-manager::order-item: select-all' |trans }}</span>
                    </form>
                    <div class="btn-group" id="myDropdown">
                        <button class="btn dropdown-toggle" data-toggle="dropdown">{{ 'order-manager::order-item: create-basket' |trans }}<span class="caret"></span></button>
                        <ul class="dropdown-menu">
                            <li type="validated" class="basket-btn">
                                <a>{{ 'order-manager::order-item: with-validated-items' |trans }}</a>
                            </li>
                            <li class="divider"></li>
                            <li type="denied" class="basket-btn">
                                <a>{{ 'order-manager::order-item: with-denied-items' |trans }}</a>
                            </li>
                            <li class="divider"></li>
                            <li type="selected" class="basket-btn disabled">
                                <a>{{ 'order-manager::order-item: with-selected-items' |trans }}</a>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="scrollable-table">
                    <table class="table-order">
                        <tbody>
                        {% for element in order.getElements() %}
                            <tr id="element_{{ loop.index }}" class="order_row {% if element.getOrderMaster() is none %}selectable{% else %}{% if element.getDeny() == true %}selectable denied{% else %}selectable validated{% endif %}{% endif %}" elementids="{{element.getSbasId(app)}}_{{element.getRecordId()}}">
                                <td width="10%" align="center">
                                    {% if element.getOrderMaster() %}
                                        {% set name = element.getOrderMaster().getDisplayName() %}
                                        {% if element.getDeny() == true %}
                                            {% set title %}
                                                {% trans with {'%name%' : name} %}Document refuse par %name%{% endtrans %}
                                            {% endset %}
                                            {% set title_send %}
                                                {% trans %}Forcer l'envoi du document{% endtrans %}
                                            {% endset %}
                                            <img style="cursor:help;" src="/assets/common/images/icons/delete.png" title="{% spaceless %}{{title|e}}{% endspaceless %}" />
                                            <img style="cursor:pointer;" class="force_sender" src="/assets/common/images/icons/reload.png" title="{% spaceless %}{{title_send|e}}{% endspaceless %}" />
                                        {% else %}
                                            {% set title %}
                                                {% trans with {'%name%' : name} %}Document envoye par %name%{% endtrans %}
                                            {% endset %}
                                            <img style="cursor:help;" src="/assets/common/images/icons/ok.png" title="{% spaceless %}{{title|e}}{% endspaceless %}" />
                                        {% endif %}
                                    {% endif %}
                                </td>
                                <td width="30%" align="center">
                                    <div id="order_wrapper_{{order.getId()}}_{{element.getBaseId()}}_{{element.getRecordId()}}" class="order_wrapper">
                                        {{ thumbnail.format(element.getRecord(app).get_thumbnail() ,80, 80, '', true, false) }}
                                        {#<div style="position:absolute;bottom:4px;right:4px;">#}
                                        {#<img class="infoTips" tooltipsrc="{{ path('prod_tooltip_technical_data', { 'sbas_id' : element.getSbasId(app), 'record_id' : element.getRecordId() }) }}" src="/assets/common/images/icons/info.gif"/>#}
                                        {#<div tooltipsrc="{{ path('prod_tooltip_preview', { 'sbas_id' : element.getSbasId(app), 'record_id' : element.getRecordId() }) }}" class="previewTips"></div>#}
                                        {#<div tooltipsrc="{{ path('prod_tooltip_caption', { 'sbas_id' : element.getSbasId(app), 'record_id' : element.getRecordId(), 'context' : 'preview' }) }}" class="captionRolloverTips"></div>#}
                                        {#</div>#}
                                        <input type="hidden" name="order_element_id" value="{{element.getId()}}"/>
                                    </div>
                                </td>
                                <td width="60%" align="center">
                                    <span>{{element.getRecord(app).getOriginalName() }}</span>
                                </td>
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>


            <div id="order_detail" style="width:60%;">
                <div class="external-order-action" id="order-action" style="display:none; margin: 0 0 1.2em 30px;">
                    <span class="action-text">{{ 'order-manager::order-item: refused-previously' | trans }}</span>
                    <button class="btn deny outline"><i class="fa fa-times" aria-hidden="true"></i>{{ 'Deny' | trans }}
                    </button>
                    <button class="btn btn-primary send outline"><i class="fa fa-check"
                                                                    aria-hidden="true"></i>{{ 'Send' | trans }}</button>
                    <button class="btn reset outline"><i class="fa fa-refresh"
                                                         aria-hidden="true"></i>{{ 'order-manager::order-item: reset' | trans }}
                    </button>
                    <img src="/assets/common/images/icons/loader000000.gif" class="activity_indicator" style="display:none;"/>
                    <input name="order_id" type="hidden" value="{{ order.getId() }}" />
                </div>
                <div id="wrapper-padding">
                    <div id="preview-layout">
                        {% include 'common/preview.html.twig' with {'record': order.getElements()[0].getRecord(app)}%}
                    </div>
                    <div id="info-header">
                        <span class="fa-stack infoTips">
                            <i class="fa fa-circle fa-stack-2x" aria-hidden="true" style="color:#4990E2"></i>
                            <i class="fa fa-info fa-stack-1x" aria-hidden="true" style="color:#FFF"></i>
                        </span>
                        <span class="info-text">{{ 'order-manager::order-item: information' | trans }}</span>
                    </div>
                    <div id="caption-layout">
                        {% include 'common/caption.html.twig' with {'record': order.getElements()[0].getRecord(app), 'view': 'preview' }%}
                    </div>
                </div>
                <div id="wrapper-multiple">
                    <div id="preview-layout-multiple">
                        <span class="title">0</span>
                        <h4 class="sub-title">{{ 'order-manager::order-item: selected-records' | trans }}</h4>
                        <img class="record record_image imgTips zoomable thumb" oncontextMenu="return(false);"
                             style="width:150px;height:150px;"
                             src="/assets/common/images/icons/substitution/image_jpg.png" ondragstart="return false;"/>
                        <div id="text-content"></div>
                    </div>
                    <div id="order-action" style="color:#333;">
                        <button class="btn deny outline"><i class="fa fa-times"
                                                            aria-hidden="true"></i>{{ 'Deny' | trans }}</button>
                        <button class="btn btn-primary send outline"><i class="fa fa-check"
                                                                        aria-hidden="true"></i>{{ 'Send' | trans }}
                        </button>
                        <button class="btn reset outline"><i class="fa fa-refresh"
                                                             aria-hidden="true"></i>{{ 'order-manager::order-item: reset' | trans }}
                        </button>
                        <img src="/assets/common/images/icons/loader000000.gif" class="activity_indicator" style="display:none;"/>
                        <input name="order_id" type="hidden" value="{{ order.getId() }}" />
                    </div>
                </div>
                <div id="wrapper-no-item">
                    <img style="width:150px;height:150px;" src="/assets/common/images/icons/substitution/image_jpg.png">
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    var defaultTitle = '{{ 'order-manager::order-list: order-id' | trans }} '
        + {{ order.getId() }} + ' {{ 'order-manager::order-item: of' |trans }} '
        + '{{ order.getCreatedOn()|date('d/m/Y') }}'
        + ' {{ 'order-manager::order-item: by' |trans }} '
        + '{{ order.getUser().getDisplayName() }}';

    var orderItemData =  {
        path: '{{ path('prod_orders') }}',
        userEmail: '{{ order.getUser().getEmail() }}',
        subject: '{{ 'order-manager::mail: your-order-of' | trans }} {{ 'order-manager::order-item: number' |trans }} '
            + {{ order.getId() }} + ' {{ 'order-manager::order-item: of' |trans }} '
            + '{{ order.getCreatedOn()|date('d/m/Y')|e('js')|raw }}',
        body: '{{ 'Utilisation prevue:' | trans }} {{ order.getOrderUsage()|e('js')|raw }}',
        description: '{{ order.getOrderUsage()|e('js')|raw }}',
        translatedText: {
            rejected: '{{ 'order-manager::order-item: rejected-item' |trans }}',
            accepted: '{{ 'order-manager::order-item: accepted-item' |trans }}',
            selected: '{{ 'order-manager::order-item: selected-item' |trans }}',
            moreText: '{{ 'order-manager::order-item: more' | trans }}',
            lessText: '{{ 'order-manager::order-item: less' | trans }}',
            dialogTitle: '{{ 'order-manager::order-item:Create-Basket' | trans }}',
            createTitle: '{{ 'order-manager::order-item: create' |trans }}',
            defaultBasketTitle: defaultTitle,
            message: '{{ 'order-manager::order-item: warning-message-close' |trans }}',
            validation: '{{ 'order-manager::order-item:Validation' | trans }}',
            submit: '{{ 'order-manager::order-item: submit' |trans }}',
            reset: '{{ 'order-manager::order-item: reset' |trans }}',
            alreadyValidated: '{{ 'order-manager::order-item: already-validated' | trans }}',
            refusedPreviously: '{{ 'order-manager::order-item: refused-previously' | trans }}',
            youHaveValidated: '{{ 'order-manager::order-item: you-have-validated' |trans }}',
            youHaveDenied: '{{ 'order-manager::order-item: you-have-denied' |trans }}',
            item: '{{ 'order-manager::order-item: item' |trans }}',
            itemsAlreadySent: '{{ 'order-manager::order-item: items-already-sent' | trans }}',
            itemsWaitingValidation: '{{ 'order-manager::order-item: items-waiting-validation' | trans }}',
            nonSentItems: '{{ 'order-manager::order-item: for-non-sent-items' | trans }}'
        }
    }

</script>