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

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

{block name="page-title"}{intl l='Store'}{/block}

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

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

    <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>{intl l="Store"}</li>
        </ul>

		<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="Store configuration"}
					</div>
                </div>

                <div class="form-container">
                    <div class="row">
                        <div class="col-md-12">
                            {form name='thelia.configuration.store'}
	 						<form method="POST" action="{url path='/admin/configuration/store/save'}" {form_enctype}>
                                {form_hidden_fields}

                                {form_field field='success_url'}
                                    <input type="hidden" name="{$name}" value="{url path='/admin/configuration'}">
                                {/form_field}
                                {include
                                    file = "includes/inner-form-toolbar.html"
                                    hide_flags = true

                                    page_url  = "{url path='/admin/configuration/store'}"
                                    close_url = "{url path='/admin/configuration'}"
                                }
                                <div class="row">
                                    <div class="col-md-6">
                                        <p class="title title-without-tabs">{intl l='General'}</p>

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

                                        <fieldset>
                                            {render_form_field field='store_name'}
                                            {render_form_field field='store_description'}
                                            {render_form_field field='store_business_id'}

                                            <p class="title title-without-tabs">{intl l='Email addresses'}</p>

                                            {render_form_field field='store_email'}
                                            {render_form_field field='store_notification_emails'}

                                            <p class="title title-without-tabs">{intl l='Media'}</p>

                                            <div class="row">
                                                <div class="col-md-10">
                                                    {render_form_field field='favicon_file'}
                                                </div>
                                                <div class="col-md-2">
                                                    {local_media type="favicon" width=64 height=64}
                                                    <img id="preview_favicon" src="{$MEDIA_URL}" width="64" height="64"/>
                                                    {/local_media}
                                                </div>
                                            </div>

                                            <div class="row">
                                                <div class="col-md-10">
                                                    {render_form_field field='logo_file'}
                                                </div>
                                                <div class="col-md-2">
                                                    {local_media type="logo"}
                                                    <img id="preview_logo" src="{$MEDIA_URL}" style="max-width: 100%"/>
                                                    {/local_media}
                                                </div>
                                            </div>

                                            <div class="row">
                                                <div class="col-md-8">
                                                    {render_form_field field='banner_file'}
                                                </div>
                                                <div class="col-md-4">
                                                    {local_media type="banner"}
                                                    <img id="preview_banner" src="{$MEDIA_URL}" style="max-width: 100%"/>
                                                    {/local_media}
                                                </div>
                                            </div>

                                        </fieldset>
                                    </div>

                                    <div class="col-md-6">
                                        <fieldset>
                                            <p class="title title-without-tabs">{intl l="Store address"}</p>

                                            {render_form_field field='store_address1'}
                                            {render_form_field field='store_address2' show_label=false}
                                            {render_form_field field='store_address3' show_label=false}

                                            <div class="row">
                                                <div class="col-md-3">
                                                    {render_form_field field='store_zipcode'}
                                                </div>
                                                <div class="col-md-9">
                                                    {render_form_field field='store_city'}
                                                </div>
                                            </div>

                                            {custom_render_form_field field='store_country'}
                                                <select {form_field_attributes field='store_country'}>
                                                    {loop type="country" name="country1"}
                                                        <option value="{$ID}" {if {$value} == $ID || (empty($value) && $IS_DEFAULT)}selected{/if}>{$TITLE}</option>
                                                    {/loop}
                                                </select>
                                            {/custom_render_form_field}

                                            <p class="title title-without-tabs">{intl l='Phone &amp; Fax'}</p>

                                            <div class="row">
                                                <div class="col-md-6">
                                                    {render_form_field field='store_phone'}
                                                </div>
                                                <div class="col-md-6">
                                                    {render_form_field field='store_fax'}
                                                </div>
                                            </div>

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

                                {include
                                file = "includes/inner-form-toolbar.html"
                                hide_flags = true
                                page_bottom = true

                                page_url  = "{url path='/admin/configuration/store'}"
                                close_url = "{url path='/admin/configuration'}"
                                }

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

{block name="javascript-last-call"}
    <script>
        function readURL(input, preview_id) {
            if (input.files && input.files[0]) {
                var reader = new FileReader();

                reader.onload = function (e) {
                    $(preview_id).attr('src', e.target.result);
                };

                reader.readAsDataURL(input.files[0]);
            }
        }

        $("#favicon_file").change(function(){
            readURL(this, '#preview_favicon');
        });

        $("#logo_file").change(function(){
            readURL(this, '#preview_logo');
        });

        $("#banner_file").change(function(){
            readURL(this, '#preview_banner');
        });
    </script>
    {hook name="config-store.js" location="config-store-js" }
{/block}
