{extends file="layout.tpl"}

{* Security *}
{block name="no-return-functions" prepend}
    {check_auth role="CUSTOMER" login_tpl="login"}
{/block}

{* Body Class *}
{block name="body-class"}page-address{/block}

{* Breadcrumb *}
{block name='no-return-functions' append}
    {$breadcrumbs = [
        ['title' => {intl l="Account"}, 'url'=>{url path="/account"}],
        ['title' => {intl l="Add a new address"}, 'url'=>{url path="/address/create"}]
    ]}
{/block}

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

    <article class="col-main" role="main" aria-labelledby="main-label">

        <h1 id="main-label" class="page-header">{intl l="Create New Address"}</h1>

        {hook name="address-create.top"}

        {form name="thelia.front.address.create"}
        <form id="form-address" class="form-horizontal" action="{url path="/address/create"}" method="post">
            {form_field field='success_url'}
                {if $value}
                {$next_url=$value}
                {else}
                {$next_url=$smarty.get.next|default:{url path="/account"}}
                {/if}
                <input type="hidden" name="{$name}" value="{$next_url nofilter}" />
            {/form_field}

            {form_field field='error_message'}
                <input type="hidden" name="{$name}" value="{intl l="missing or invalid data"}" />
            {/form_field}
            {form_hidden_fields}
            {if $form_error}<div class="alert alert-danger">{$form_error_message}</div>{/if}

            {hook name="address-create.form-top"}

            <fieldset class="panel panel-default">
                <div class="panel-heading">
                    {intl l="Address"}
                </div>

                <div class="panel-body">
                    {form_field field="label"}
                    <div class="form-group group-label{if $error} has-error{/if}">
                        <label class="control-label col-sm-3" for="{$label_attr.for}">{$label}:{if $required} <span class="required">*</span>{/if}</label>

                        <div class="control-input col-sm-5">
                            <input type="text" name="{$name}" value="{$value}" id="{$label_attr.for}" class="form-control" minlength="2" maxlength="255" placeholder="{intl l="Placeholder address label"}"{if $required} aria-required="true" required{/if}{if !$value || $error} autofocus{/if}>
                            {if $error }
                                <span class="help-block">{$message}</span>
                                {assign var="error_focus" value="true"}
                            {elseif !$value}
                                {assign var="error_focus" value="true"}
                            {/if}
                        </div>
                    </div>
                    <!--/.form-group-->
                    {/form_field}

                    {form_field field="title"}
                        <div class="form-group group-title{if $error} has-error{/if}">
                            <label class="control-label col-sm-3" for="{$label_attr.for}">{$label}:{if $required} <span class="required">*</span>{/if}</label>
                            <div class="control-input col-sm-5">
                                <select name="{$name}" id="{$label_attr.for}" class="form-control"{if $required} aria-required="true" required{/if}{if !isset($error_focus) && $error} autofocus{/if}>
                                    <option value="">-- {intl l="Select Title"} --</option>
                                    {loop type="title" name="title.list"}
                                        <option value="{$ID}" {if $value == $ID}selected{/if} >{$LONG}</option>
                                    {/loop}
                                </select>
                                {if $error }
                                    <span class="help-block">{$message}</span>
                                    {assign var="error_focus" value="true"}
                                {/if}
                            </div>
                        </div><!--/.form-group-->
                    {/form_field}

                    {form_field field="firstname"}
                        <div class="form-group group-firstname {if $error}has-error{/if}">
                            <label class="control-label col-sm-3" for="{$label_attr.for}">{$label}:{if $required} <span class="required">*</span>{/if}</label>

                            <div class="control-input col-sm-5">
                                <input type="text" name="{$name}" value="{$value}" id="{$label_attr.for}" class="form-control" maxlength="255" placeholder="{intl l="Placeholder firstname"}"{if $required} aria-required="true" required{/if}{if !isset($error_focus) && $error} autofocus{/if}>
                                {if $error }
                                    <span class="help-block">{$message}</span>
                                    {assign var="error_focus" value="true"}
                                {/if}
                            </div>
                        </div>
                        <!--/.form-group-->
                    {/form_field}
                    <!--/.form-group-->

                    {form_field field="lastname"}
                        <div class="form-group group-lastname {if $error}has-error{/if}">
                            <label class="control-label col-sm-3" for="{$label_attr.for}">{$label}:{if $required} <span class="required">*</span>{/if}</label>

                            <div class="control-input col-sm-5">
                                <input type="text" name="{$name}" value="{$value}" id="{$label_attr.for}" class="form-control" maxlength="255" placeholder="{intl l="Placeholder lastname"}"{if $required} aria-required="true" required{/if}{if !isset($error_focus) && $error} autofocus{/if}>
                                {if $error }
                                    <span class="help-block">{$message}</span>
                                    {assign var="error_focus" value="true"}
                                {/if}
                            </div>
                        </div>
                        <!--/.form-group-->
                    {/form_field}

                    {form_field field="company"}
                      <div class="form-group group-company{if $error} has-error{/if}">
                        <label class="control-label col-sm-3" for="{$label_attr.for}">{$label}:{if $required} <span class="required">*</span>{/if}</label>
                          <div class="control-input col-sm-5">
                            <input type="text" name="{$name}" value="{$value}" id="{$label_attr.for}" class="form-control" maxlength="255" placeholder="{intl l="Placeholder company"}" value="{$value}"{if $required} aria-required="true" required{/if}{if !isset($error_focus) && $error} autofocus{/if}>
                            {if $error }
                              <span class="help-block">{$message}</span>
                              {assign var="error_focus" value="true"}
                            {/if}
                          </div>
                      </div><!--/.form-group-->
                    {/form_field}

                    {form_field field="address1"}
                        <div class="form-group group-address1 {if $error}has-error{/if}">
                            <label class="control-label col-sm-3" for="{$label_attr.for}">{$label}:{if $required} <span class="required">*</span>{/if}</label>

                            <div class="control-input col-sm-5">
                                <input type="text" name="{$name}" value="{$value}" id="{$label_attr.for}" class="form-control" maxlength="255" placeholder="{intl l="Placeholder address1"}"{if $required} aria-required="true" required{/if}{if !isset($error_focus) && $error} autofocus{/if}>
                                {if $error }
                                    <span class="help-block">{$message}</span>
                                    {assign var="error_focus" value="true"}
                                {/if}
                            </div>
                        </div>
                        <!--/.form-group-->
                    {/form_field}

                    {form_field field="address2"}
                        <div class="form-group group-address2 {if $error}has-error{/if}">
                            <label class="control-label col-sm-3" for="{$label_attr.for}">{$label}:{if $required} <span class="required">*</span>{/if} </label>

                            <div class="control-input col-sm-5">
                                <input type="text" name="{$name}" value="{$value}" id="{$label_attr.for}" class="form-control" maxlength="255" placeholder="{intl l="Placeholder address2"}"{if $required} aria-required="true" required{/if}{if !isset($error_focus) && $error} autofocus{/if}>
                                {if $error }
                                    <span class="help-block">{$message}</span>
                                    {assign var="error_focus" value="true"}
                                {/if}
                            </div>
                        </div>
                        <!--/.form-group-->
                    {/form_field}

                    {form_field field="zipcode"}
                        <div class="form-group group-zipcode {if $error}has-error{/if}">
                            <label class="control-label col-sm-3" for="{$label_attr.for}">{$label}:{if $required} <span class="required">*</span>{/if}</label>

                            <div class="control-input col-sm-5">
                                <input type="text" name="{$name}" value="{$value}" id="{$label_attr.for}" class="form-control" maxlength="10" placeholder="{intl l="Placeholder zipcode"}"{if $required} aria-required="true" required{/if}{if !isset($error_focus) && $error} autofocus{/if}>
                                {if $error }
                                    <span class="help-block">{$message}</span>
                                    {assign var="error_focus" value="true"}
                                {/if}
                            </div>
                        </div>
                        <!--/.form-group-->
                    {/form_field}

                    {form_field field="city"}
                        <div class="form-group group-city {if $error}has-error{/if}">
                            <label class="control-label col-sm-3" for="{$label_attr.for}">{$label}:{if $required} <span class="required">*</span>{/if}</label>

                            <div class="control-input col-sm-5">
                                <input type="text" name="{$name}" value="{$value}" id="{$label_attr.for}" class="form-control" maxlength="255" placeholder="{intl l="Placeholder city"}"{if $required} aria-required="true" required{/if}{if !isset($error_focus) && $error} autofocus{/if}>
                                {if $error }
                                    <span class="help-block">{$message}</span>
                                    {assign var="error_focus" value="true"}
                                {/if}
                            </div>
                        </div>
                        <!--/.form-group-->
                    {/form_field}

                    {form_field field="country"}
                        {assign var="customer_country_id" value={$value|default:$COUNTRY}}
                        {$countryFieldId=$label_attr.for}
                        <div class="form-group group-country {if $error}has-error{/if}">
                            <label class="control-label col-sm-3" for="{$label_attr.for}">{$label}:{if $required} <span class="required">*</span>{/if}</label>
                            <div class="control-input col-sm-5">
                                <select name="{$name}" id="{$label_attr.for}" class="form-control"{if $required} aria-required="true" required{/if}{if !isset($error_focus) && $error} autofocus{/if}>
                                    <option value="">-- {intl l="Select Country"} --</option>
                                    {loop type="country" name="country.list" order="alpha"}
                                        <option value="{$ID}" {if $value == $ID}selected{/if} >{$TITLE}</option>
                                    {/loop}
                                </select>
                                {if $error }
                                    <span class="help-block">{$message}</span>
                                    {assign var="error_focus" value="true"}
                                {/if}
                            </div>
                        </div><!--/.form-group-->
                    {/form_field}

                    {form_field field="state"}
                    {assign var="customer_state_id" value={$value|default:$STATE}}
                        <div class="form-group group-state {if $error}has-error{/if}">
                            <label class="control-label col-sm-3" for="{$label_attr.for}">{$label}:{if $required} <span class="required">*</span>{/if}</label>
                            <div class="control-input col-sm-5">
                                <select name="{$name}" id="{$label_attr.for}"
                                        data-thelia-state="1" data-thelia-country="#{$countryFieldId}" data-thelia-toggle=".group-state"
                                        class="form-control"{if !isset($error_focus) && $error} autofocus{/if}>
                                    <option value="">-- {intl l="Select State"} --</option>
                                    {loop type="state" name="state.list"}
                                        <option value="{$ID}" data-country="{$COUNTRY}"
                                                {if $customer_state_id == $ID}selected{/if}
                                        >{$TITLE}</option>
                                    {/loop}
                                </select>
                                {if $error }
                                    <span class="help-block">{$message}</span>
                                    {assign var="error_focus" value="true"}
                                {/if}
                            </div>
                        </div><!--/.form-group-->
                    {/form_field}

                    {form_field field="phone"}
                        <div class="form-group group-phone {if $error}has-error{/if}">
                            <label class="control-label col-sm-3" for="{$label_attr.for}">{$label}:{if $required} <span class="required">*</span>{/if}</label>

                            <div class="control-input col-sm-5">
                                <input type="text" name="{$name}" value="{$value}" id="{$label_attr.for}" class="form-control" maxlength="20" placeholder="{intl l="Placeholder phone"}"{if $required} aria-required="true" required{/if}{if !isset($error_focus) && $error} autofocus{/if}>
                                {if $error }
                                    <span class="help-block">{$message}</span>
                                    {assign var="error_focus" value="true"}
                                {/if}
                            </div>
                        </div>
                        <!--/.form-group-->
                    {/form_field}

                    {form_field field="cellphone"}
                        <div class="form-group group-cellphone {if $error}has-error{/if}">
                            <label class="control-label col-sm-3" for="{$label_attr.for}">{$label}:{if $required} <span class="required">*</span>{/if}</label>

                            <div class="control-input col-sm-5">
                                <input type="text" name="{$name}" value="{$value}" id="{$label_attr.for}" class="form-control" maxlength="20" placeholder="{intl l="Placeholder cellphone"}"{if $required} aria-required="true" required{/if}{if !isset($error_focus) && $error} autofocus{/if}>
                                {if $error }
                                    <span class="help-block">{$message}</span>
                                    {assign var="error_focus" value="true"}
                                {/if}
                            </div>
                        </div>
                        <!--/.form-group-->
                    {/form_field}
                </div>
            </fieldset>

            {form_field field="is_default"}
            <div class="form-group group-primary">
                <div class="control-input col-sm-5 col-sm-offset-3">
                    <div class="checkbox">
                        <label class="control-label" for="{$label_attr.for}">
                            <input type="checkbox" name="{$name}" id="{$label_attr.for}" value="1"> {$label}
                        </label>
                    </div>
                </div>
            </div>
            <!--/.form-group-->
            {/form_field}

            {hook name="address-create.form-bottom"}

            <div class="form-group group-btn">
                <div class="control-btn col-sm-5 col-sm-offset-3">
                    <button type="submit" class="btn btn-primary"><i class="fa fa-chevron-right"></i> {intl l="Create"}</button>
                </div>
            </div>
            <!--/.form-group-->
        </form>
        {/form}

        {hook name="address-create.bottom"}
    </article>

    </div><!-- /.layout -->
{/block}

{block name="stylesheet"}
{hook name="address-create.stylesheet"}
{/block}

{block name="after-javascript-include"}
{hook name="address-create.after-javascript-include"}
{/block}

{block name="javascript-initialization"}
{hook name="address-create.javascript-initialization"}
{/block}
