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

{block name="no-return-functions"}
    {$admin_current_location = 'configuration'}
{/block}

{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 configuration"}</a></li>
        </ul>

        {hook name="shipping-zones.top" 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" id=$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 configuration'}
                            </caption>

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

                                   {hook name="shipping-zones.table-header" 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" order="code"}
                                <tr>
                                   <td><a href="{url path="/admin/configuration/shipping_zones/update/%id" id=$ID}">{$CODE} - {$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" visible="*"}
                                                {$countries = "$countries, $TITLE"}
                                            {/loop}
                                            {$countries = ltrim($countries, ', ')}

                                            <a href="{url path="/admin/configuration/shipping_configuration/update/%id" id=$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>
                                    {hook name="shipping-zones.table-row" location="shipping_zones_table_row" module_id={$ID} }

                                    <td class="actions">
                                       {include file='renderer/buttons.html' buttons=[
                                            [
                                                'type' => 'edit',
                                                'class' => 'shipping-zones-change',
                                                'title' => {intl l='Change this shipping zone'},
                                                'href' => {url path="/admin/configuration/shipping_zones/update/%id" id=$ID},
                                                'auth' => ['resource' => 'admin.configuration.shipping-zone']
                                            ]
                                        ]}
                                    </td>
                                </tr>
                                {/loop}

                                {elseloop rel="delivery.list"}
                                    <tr>
                                        <td colspan="3">
                                            <div class="alert alert-info">
                                                {intl l="No shipping zone defined yet. Click the + button to create one."}
                                            </div>
                                        </td>
                                    </tr>
                                {/elseloop}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>

        {hook name="shipping-zones.bottom" location="shipping_zones_bottom" }

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

{block name="javascript-last-call"}
    {hook name="shipping-zones.js" location="shipping-zones-js" }
{/block}
