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

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

{block name="page-title"}{intl l='Edit a country'}{/block}

{block name="check-resource"}admin.configuration.country{/block}
{block name="check-access"}update{/block}

{block name="main-content"}
    <div class="countries edit-country">

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

            {loop name="country_edit" type="country" id="$country_id" backend_context="1" lang="$edit_language_id" visible="*"}

                <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/countries'}">{intl l="Countries"}</a></li>
                    <li>{intl l='Editing country "%name"' name="{$TITLE}"}</li>
                </ul>

            {hook name="country-edit.top" country_id=$country_id}

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

        					<div class="col-md-12 title title-without-tabs">
        					   {intl l='Edit country "%name"' name="{$TITLE}"}
        					</div>

                            <div class="form-container">
                                <div class="col-md-12">

        						    {form name="thelia.admin.country.modification"}
        						    	<form method="POST" action="{url path="/admin/configuration/country/save/%id" id=$ID}" {form_enctype} class="clearfix">
                                            {include
                                                file = "includes/inner-form-toolbar.html"
                                                hide_submit_buttons = false

                                                page_url  = {url path="/admin/configuration/country/update/%id" id=$ID}
                                                close_url = {url path="/admin/configuration/countries"}
                                            }

                                            {* Be sure to get the country ID, even if the form could not be validated *}
                                            <input type="hidden" name="country_id" value="{$country_id}" />

                                            {form_hidden_fields exclude="locale"}

                                            {render_form_field field='success_url' value={url path="/admin/configuration/countries"}}
                                            {render_form_field field='locale' value={$edit_language_locale}}

                                            {if $form_error}<div class="alert alert-danger">{$form_error_message}</div>{/if}

                                            <div class="row">
            	                                <div class="col-md-6">
                                                    {render_form_field field="visible"}

                                                    {include file="includes/standard-description-form-fields.html"}
                                                </div>

                                                <div class="col-md-6">
                                                    {render_form_field field="isocode"}
                                                    {render_form_field field="isoalpha2"}
                                                    {render_form_field field="isoalpha3"}

                                                    {render_form_field field="has_states"}
                                                    {render_form_field field="need_zip_code"}
                                                    {render_form_field field="zip_code_format"}

                                                    <div class="panel panel-default">
                                                        <div class="panel-heading">
                                                            <h3 class="panel-title">{intl l="Shipping zones for this country"}</h3>
                                                        </div>
                                                        <div class="panel-body">
                                                            {ifloop rel="country-areas"}
                                                                <ul class="list-unstyled">
                                                                    {loop name="country-areas" type="area" country=$country_id backend_context="1"}
                                                                        <li><a href="">{$NAME}</a></li>
                                                                    {/loop}
                                                                </ul>
                                                            {/ifloop}
                                                            {elseloop rel="country-areas"}
                                                                <div class="alert alert-warning">{intl l="This country is not included in any shipping zone"}</div>
                                                            {/elseloop}
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </form>
        							{/form}

                                    {ifloop rel="states"}

                                    {loop type="auth" name="can_change" role="ADMIN" resource="admin.configuration.state" access="UPDATE"}
                                        {$canEditState=true}
                                    {/loop}

                                    <div class="panel panel-default">
                                        <div class="panel-heading">
                                            <h3 class="panel-title">{intl l="States/provinces assigned to this country"}</h3>
                                        </div>
                                        <div class="panel-body">
                                            <div class="table-responsive">
                                                <table class="table table-striped table-condensed">
                                                    <tbody>
                                                    {loop name="states" type="state" country=$country_id visible="*" backend_context="1"}
                                                    <tr>
                                                        <td>{$ID}. {$TITLE}</td>
                                                        {if $canEditState}
                                                            <td class="text-center">
                                                                <a title="{intl l='Change this state'}" href="{url path="/admin/configuration/state/update/%id" id=$ID}">{intl l="Edit"}</a>
                                                            </td>
                                                        {/if}
                                                    </tr>
                                                    {/loop}
                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>
                                    </div>
                                    {/ifloop}
        						</div>
        					</div>

        				</div>
        			</div>

        		</div>

            {hook name="country-edit.bottom" country_id=$country_id}

    		{/loop}

            {elseloop rel="country_edit"}
                <div class="row">
                    <div class="col-md-12">
                        <div class="alert alert-error">
                            {intl l="Sorry, country ID=%id was not found." id={$country_id}}
                        </div>
                    </div>
                </div>
            {/elseloop}

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

{block name="javascript-last-call"}
    {hook name="country.edit-js" location="country-edit-js" country_id=$country_id }
    {hook name="wysiwyg.js" location="wysiwyg-country-edit-js" }
{/block}