{extends file="admin-layout.tpl"}

{block name="page-title"}{intl l='Thelia Shipping zones'}{/block}

{block name="check-resource"}admin.configuration.shipping-zone{/block}
{block name="check-access"}view{/block}

{block name="main-content"}
<div class="shipping-zones">

    <div id="wrapper" class="container">

        <ul class="breadcrumb">
            <li><a href="{url path='/admin/home'}">{intl l="Home"}</a></li>
            <li><a href="{url path='/admin/configuration'}">{intl l="Configuration"}</a></li>
            <li><a href="{url path='/admin/configuration/shipping_zones'}">{intl l="Shipping zones"}</a></li>
        </ul>

        {module_include location='shipping_zones_top'}

        <div class="row">
            <div class="col-md-12">
                <div class="general-block-decorator">

                    {ifloop rel="area-not-attached"}
                    <div class="row">
                        <div class="col-md-12">
                            <div class="alert alert-warning">
                                {intl l='<strong>Warning</strong>, some of your shipping zones are not attached to any delivery module:'}
                                {loop name="area-not-attached" type="area" unassigned=true}
                                    <a href="{url path="/admin/configuration/shipping_configuration/update/$ID"}" title="{intl l='Edit this delivery zone'}">{$NAME}</a>{if $LOOP_COUNT < $LOOP_TOTAL},{else}.{/if}
                                {/loop}
                            </div>
                        </div>
                    </div>
                    {/ifloop}

                    <div class="table-responsive">
                        <table class="table table-striped table-condensed table-left-aligned">

                            <caption>
                               {intl l='Shipping zones'}
                            </caption>

                            <thead>
    	                        <tr>
                                    <th>{intl l="Delivery module"}</th>
                                    <th>{intl l="Shipping zones for this module"}</th>

                                   {module_include location='shipping_zones_table_header'}

                                   <th class="text-center">{intl l="Actions"}</th>
    	                        </tr>
                            </thead>

                            <tbody>
                                {loop type="module" module_type="2" active="*" name="delivery.list" backend_context="1"}
                                <tr>
                                   <td><a href="{url path="/admin/configuration/shipping_zones/update/$ID"}">{$TITLE}</a></td>
                                    <td>
                                        {loop name="area.module.associated" type="area" with_zone=$ID backend_context="1"}
                                            {$countries = ''}
                                            {loop name="country-area" type="country" area=$ID backend_context="1"}
                                                {$countries = "$countries, $TITLE"}
                                            {/loop}
                                            {$countries = ltrim($countries, ', ')}

                                            <a href="{url path="/admin/configuration/shipping_configuration/update/$ID"}" title="{$countries}">{$NAME}</a>{if $LOOP_COUNT < $LOOP_TOTAL},{/if}
                                        {/loop}
                                        {elseloop rel="area.module.associated"}
                                            {intl l="There are no shipping zones attached to this module."}
                                        {/elseloop}
                                    </td>
                                    {module_include location='shipping_zones_table_row'}

                                    <td class="text-center">
                                        <div class="btn-group">
                                           {loop type="auth" name="can_change" role="ADMIN" resource="admin.configuration.shipping-zone" access="UPDATE"}
                                               <a class="btn btn-default btn-xs shipping-zones-change" title="{intl l='Change this shipping zone'}" href="{url path="/admin/configuration/shipping_zones/update/$ID"}"><i class="glyphicon glyphicon-edit"></i></a>
                                           {/loop}
                                        </div>
                                    </td>
                                </tr>
                                {/loop}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>

        {module_include location='shipping_zones_bottom'}

    </div>
</div>
{/block}

{block name="javascript-last-call"}
    {module_include location='shipping-zones-js'}
{/block}