<div class="row">
    <!-- Errors -->
    {loop name="checkrights.colissimo" type="colissimo.check.rights"}
    <div class="alert alert-danger">
        <p>{$ERRMES} {$ERRFILE} | {intl d='artabanmarketplacecolissimo.bo.default' l="Please change the access rights"}.</p>
    </div>
    {/loop}
</div>

{elseloop rel="checkrights.colissimo"}

<div class="alert alert-info">
    <p>{intl d='artabanmarketplacecolissimo.bo.default' l="Colissimo Module allows to send your products all around the world with La Poste."}</p>
</div>

<div class="modal fade" id="freeshipping-failed" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">

            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3>{intl d='artabanmarketplacecolissimo.bo.default' l="An error occured"}</h3>
            </div>
            <div class="modal-body" id="freeshipping-failed-body">

            </div>
        </div>
    </div>
</div>

<div class="general-block-decorator">
    <div class="row">
        <div class="col-md-12">
            {form name="colissimo.configuration"}
            <form method="POST" action="{url path='/admin/module/artabanmarketplacecolissimo/configuration/update'}">
                {form_hidden_fields form=$form}

                {form_field form=$form field="enabled"}
                <div class="form-group">
                    <label class="control-label" for="{$label_attr.for}">
                        <input type="checkbox" name="{$name}" id="{$label_attr.for}" {if $value}checked{/if} />
                        {$label}
                        {form_error form=$form field="enabled"}
                        <br />
                        <span class="error">{$message}</span>
                        {/form_error}
                    </label>
                    {if ! empty($label_attr.help)}
                    <span class="help-block">{$label_attr.help}</span>
                    {/if}
                </div>
                {/form_field}

                <button type="submit" name="colissimo_save_configuration" value="save" class="form-submit-button btn btn-sm btn-default" title="{intl d='artabanmarketplacecolissimo.bo.default' l='Save'}">
                    {intl d='artabanmarketplacecolissimo.bo.default' l='Save'}
                </button>
            </form>
            {/form}
        </div>
    </div>
</div>

<div class="general-block-decorator">
    <div class="row">
        <div class="col-md-12">
            <!-- Tab menu -->
            <ul id="tabbed-menu" class="nav nav-tabs">
                <li class="active"><a data-toggle="tab" href="#export">{intl d='artabanmarketplacecolissimo.bo.default' l="Export expeditor inet file"}</a> </li>
                <li class="{if $tab eq "1"}active{/if}"><a data-toggle="tab" href="#prices_slices_tab">{intl d='artabanmarketplacecolissimo.bo.default' l="Price slices"}</a></li>
            </ul>

            <div class="tab-content">

                <!-- Export tab -->
                <div id="export" class="tab-pane active form-container">
                    {form name="colissimo.export.form"}
                    {if $form_error}<div class="alert alert-danger">{$form_error_message}</div>{/if}
                        <form action="{url path='/admin/module/artabanmarketplacecolissimo/export'}" method="post">
                            {form_hidden_fields}
                            <div class="panel panel-default">

                                <div class="panel-heading clearfix">
                                    {intl d='artabanmarketplacecolissimo.bo.default' l="Change orders status after export"}
                                </div>

                                <div class="panel-body">
                                    <table>
                                        {form_field field="status_id"}
                                            <tr>
                                                <td>
                                                    <label for="nochange">{intl d='artabanmarketplacecolissimo.bo.default' l="Do not change"}</label>&nbsp;
                                                </td>
                                                <td>
                                                    <input type="radio" id="nochange" name="{$name}" value="nochange" checked/>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <label for="processing">{intl d='artabanmarketplacecolissimo.bo.default' l="Processing"}</label>&nbsp;
                                                </td>
                                                <td>
                                                    <input type="radio" id="processing" name="{$name}" value="processing"/>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <label for="sent">{intl d='artabanmarketplacecolissimo.bo.default' l="Sent"}*</label>&nbsp;
                                                </td>
                                                <td>
                                                    <input type="radio" id="sent" name="{$name}" value="sent"/>
                                                </td>
                                            </tr>
                                        {/form_field}
                                    </table>

                                    <span class="p">{intl d='colissimo.ai' l="*If you choose this option, the exported orders would not be available on this page anymore"}</span>
                                </div>
                            </div>

                            <!-- Order list -->
                            <table class="table table-striped table-condensed">
                                <thead>
                                    <th class="object-title">
                                        {intl d='colissimo.ai' l="REF"}
                                    </th>
                                    <th class="object-title">
                                        {intl d='colissimo.ai' l="Customer"}
                                    </th>
                                    <th class="object-title">
                                        {intl d='colissimo.ai' l="Date"}
                                    </th>
                                    <th class="object-title">
                                        {intl d='colissimo.ai' l="Total taxed amount"}
                                    </th>
                                    <th class="object-title">
                                        {intl d='colissimo.ai' l="Number of packages"}
                                    </th>
                                    <th class="object-title">
                                        {intl d='colissimo.ai' l="Packages weight"}
                                    </th>
                                    <th class="object-title">
                                        {intl d='colissimo.ai' l="Export"}
                                    </th>
                                </thead>

                                <tbody>
                                    {loop name="colissimo.notsend.loop" type="colissimo.notsend.loop"}
                                        <tr>
                                            <td>
                                                <a href="{url path="/admin/order/update/%id" id=$ID}">{$REF}</a>
                                            </td>
                                            <td>
                                                {loop type='customer' name='colissimo.customer' id=$CUSTOMER current='false'}
                                                    <a href="{url path="/admin/customer/update" customer_id=$ID}">{$LASTNAME} {$FIRSTNAME}</a>
                                                {/loop}
                                            </td>
                                            <td>
                                                {$CREATE_DATE|date_format}
                                            </td>
                                            <td>
                                                {$TOTAL_TAXED_AMOUNT} {loop name="list.socolissimo.getcurrency" type="currency" id=$CURRENCY}{$SYMBOL}{/loop}
                                            </td>
                                            <td>
                                                {form_field form=$form field="order_nb_pkg_"|cat:$ID}
                                                    <input class="form-control text-center" type="text" name="{$name}" value="1" />
                                                {/form_field}
                                            </td>
                                            <td>
                                                {form_field form=$form field="order_weight_"|cat:$ID}
                                                    <input class="form-control text-center" type="text" name="{$name}" value="0" />
                                                {/form_field}
                                            </td>
                                            <td>
                                                {form_field field="order_"|cat:$ID}
                                                    <input type="checkbox" name="{$name}" id="{$label_attr.for}" value="true" class="form-control"/>
                                                {/form_field}
                                            </td>
                                        </tr>
                                    {/loop}
                                    {elseloop rel="colissimo.notsend.loop"}
                                        <tr>
                                            <td colspan="4">
                                                <br />
                                                <div class="alert alert-info">{intl d='colissimo.ai' l="There is currently not orders to export"}</div>
                                            </td>
                                        </tr>
                                    {/elseloop}
                                </tbody>
                            </table>

                            {ifloop rel="colissimo.notsend.loop"}
                                <button type="submit" name="export_socolissimo_form" value="stay" class="form-submit-button btn btn-sm btn-default" title="{intl d='artabanmarketplacecolissimo.bo.default' l='Export'}">{intl d='artabanmarketplacecolissimo.bo.default' l='Export'}</button>
                            {/ifloop}
                        </form>
                    {/form}
                </div>

                <div id="prices_slices_tab" class="tab-pane {if $tab eq 1}active{/if} form-container">
                    <!-- checkbox free shipping -->
                    {assign var="isColissimoFreeShipping" value=0}
                    {form  name="colissimo.freeshipping.form"}
                        <br />
                        <form action="{url path="/admin/module/artabanmarketplacecolissimo/freeshipping"}" method="post" id="freeshippingform">
                            {form_hidden_fields}

                            {form_field field="freeshipping"}
                            <label>
                                {$label}
                            </label>

                            <div class="switch-small freeshipping-activation-Colissimo" data-id="0" data-on="success" data-off="danger" data-on-label="<i class='glyphicon glyphicon-ok-circle'></i>" data-off-label="<i class='glyphicon glyphicon-remove-circle'></i>">
                                <input type="checkbox" name="{$name}" {if $value}checked{assign var="isColissimoFreeShipping" value=1}{/if} />
                            </div>
                            {/form_field}
                        </form>
                    {/form}
                    <div id="table-prices-colissimo" {if $isColissimoFreeShipping eq 1} style="display:none;" {/if}>
                        <!-- Prices editing -->
                        {* -- Add price slice confirmation dialog ----------------------------------- *}
                        {loop type="area" name="list area" backend_context=true module_id=$module_id}
                        {include
                        file = "includes/generic-create-dialog.html"

                        dialog_id    = "price_slice_create_dialog_{$ID}"
                        dialog_title = {intl d='artabanmarketplacecolissimo.bo.default' l="Create a price slice"}
                        dialog_body  = "<input type=\"hidden\" name=\"operation\" value=\"add\"/>
                        <input type=\"hidden\" name=\"area\" value=\"{$ID}\" />
                        <label for=\"weight_{$ID}\">{intl d='artabanmarketplacecolissimo.bo.default' l="Weight up to ... (kg)"}</label></label>
                        <input type=\"number\" step=\"0.01\" id=\"weight_{$ID}\" name=\"weight\" value=\"1\" class=\"form-control\" pattern=\"\d+\.?\d*\" required/>
                        <label for=\"price_{$ID}\">{intl d='artabanmarketplacecolissimo.bo.default' l="Price (€)"}</label></label>
                        <input type=\"number\" step=\"0.01\" id=\"price_{$ID}\" name=\"price\" value=\"1\" class=\"form-control\" pattern=\"\d+\.?\d*\" required/>"

                        form_action="{url path="/admin/module/artabanmarketplacecolissimo/prices"}"

                        dialog_ok_label     = {intl d='artabanmarketplacecolissimo.bo.default' l="Create"}
                        dialog_cancel_label = {intl d='artabanmarketplacecolissimo.bo.default' l="Cancel"}
                        }
                        <div class="table-responsive">
                            <table class="table table-striped table-condensed table-left-aligned">
                                <caption class="clearfix">
                                    {intl d='artabanmarketplacecolissimo.bo.default' l="Area : "}{$NAME}
                                    {loop type="auth" name="can_create" role="ADMIN" module="colissimo" access="CREATE"}
                                    <a class="btn btn-default btn-primary pull-right" title="{intl d='artabanmarketplacecolissimo.bo.default' l='Create a new price slice'}" href="#price_slice_create_dialog_{$ID}" data-toggle="modal">
                                        <span class="glyphicon glyphicon-plus"></span>
                                    </a>
                                    {/loop}
                                </caption>
                                <thead>
                                <tr>
                                    <th class="col-md-3">{intl d='artabanmarketplacecolissimo.bo.default' l="Weight up to ... (kg)"}</th>
                                    <th class="col-md-5">{intl d='artabanmarketplacecolissimo.bo.default' l="Price (€)"}</th>
                                    <th class="col-md-1">{intl d='artabanmarketplacecolissimo.bo.default' l="Actions"}</th>
                                </tr>
                                </thead>
                                <tbody>
                                {loop type="colissimo" name="colissimo" area=$ID}
                                {* -- EDIT price slice confirmation dialog ----------------------------------- *}
                                {include
                                file = "includes/generic-confirm-dialog.html"

                                dialog_id    = "price_slice_edit_dialog_{$ID}_{$MAX_WEIGHT|replace:'.':'-'}"
                                dialog_title = {intl d='artabanmarketplacecolissimo.bo.default' l="Edit a price slice"}
                                dialog_message  = "<input type=\"hidden\" name=\"operation\" value=\"add\"/>
                                <input type=\"hidden\" name=\"area\" value=\"{$ID}\"/>
                                <input type=\"hidden\" name=\"weight\" value=\"{$MAX_WEIGHT}\"/>
                                <label for=\"price_edit_{$ID}_{$MAX_WEIGHT}\">{intl d='artabanmarketplacecolissimo.bo.default' l='Price (€)'}</label>
                                <input type=\"number\" step=\"0.01\" id=\"price_edit_{$ID}_{$MAX_WEIGHT}\" class=\"form-control\" name=\"price\" value=\"{$PRICE}\" pattern=\"\d+\.?\d*\" required/>"

                                form_action="{url path="/admin/module/artabanmarketplacecolissimo/prices"}"
                                dialog_ok_label     = {intl d='artabanmarketplacecolissimo.bo.default' l="Edit"}
                                dialog_cancel_label = {intl d='artabanmarketplacecolissimo.bo.default' l="Cancel"}
                                }
                                {* -- Delete price slice confirmation dialog ----------------------------------- *}
                                {include
                                file = "includes/generic-confirm-dialog.html"

                                dialog_id    = "price_slice_delete_dialog_{$ID}_{$MAX_WEIGHT|replace:'.':'-'}"
                                dialog_title = {intl d='artabanmarketplacecolissimo.bo.default' l="Delete a price slice"}
                                dialog_message  = "<input type=\"hidden\" name=\"operation\" value=\"delete\"/>
                                <input type=\"hidden\" name=\"area\" value=\"{$ID}\"/>
                                <input type=\"hidden\" name=\"weight\" value=\"{$MAX_WEIGHT}\"/>
                                {intl d='artabanmarketplacecolissimo.bo.default' l="Do you really want to delete this slice ?"}"

                                form_action="{url path="/admin/module/artabanmarketplacecolissimo/prices"}"
                                dialog_ok_label     = {intl d='artabanmarketplacecolissimo.bo.default' l="Delete"}
                                dialog_cancel_label = {intl d='artabanmarketplacecolissimo.bo.default' l="Cancel"}
                                }

                                <tr>
                                    <td>{$MAX_WEIGHT}</td>
                                    <td>{$PRICE}</td>
                                    <td>
                                        <div class="btn-group">
                                            {loop type="auth" name="can_change" role="ADMIN" module="colissimo" access="UPDATE"}
                                            <a class="btn btn-default btn-xs" title="{intl d='artabanmarketplacecolissimo.bo.default' l='Edit this price slice'}" href="#price_slice_edit_dialog_{$ID}_{$MAX_WEIGHT|replace:'.':'-'}" data-toggle="modal">
                                                <span class="glyphicon glyphicon-edit"></span>
                                            </a>
                                            <a class="btn btn-default btn-xs" title="{intl d='artabanmarketplacecolissimo.bo.default' l='Delete this price slice'}" href="#price_slice_delete_dialog_{$ID}_{$MAX_WEIGHT|replace:'.':'-'}" data-toggle="modal">
                                                <span class="glyphicon glyphicon-trash"></span>
                                            </a>
                                            {/loop}
                                        </div>
                                    </td>
                                </tr>
                                {/loop}
                                </tbody>
                            </table>
                        </div>
                        {/loop}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{/elseloop}
