{extends file="layout.tpl"}

{block name="init"}
{$brand_id={brand attr="id"}}
{/block}

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

{* Page Title *}
{block name='no-return-functions' append}
{if $brand_id}
    {loop name="brand.seo.title" type="brand" id=$brand_id limit="1"}
    {$page_title = $META_TITLE}
    {/loop}
{/if}
{/block}

{* Meta *}
{block name="meta"}
{if $brand_id}
    {loop name="brand.seo.meta" type="brand" id=$brand_id limit="1"}
        {include file="includes/meta-seo.html"}
    {/loop}
{/if}
{/block}

{* Feeds *}
{block name="feeds"}
{if $brand_id}
    <link rel="alternate" type="application/rss+xml" title="{intl l='All product in brand %title' title={brand attr='title'}}" href="{url path="/feed/brand/%lang/%brand_id" lang={lang attr='locale'} brand_id=$brand_id}"/>
{/if}
{/block}

{* Breadcrumb *}
{block name='no-return-functions' append}
{if $brand_id}
    {$breadcrumbs = []}
    {if $brand_id}
        {loop type="brand" name="brand-breadcrumb" id=$brand_id limit="1"}
        {$breadcrumbs[] = ['title' => {$TITLE}, 'url'=> {$URL nofilter}]}
        {/loop}
    {else}
        {$breadcrumbs[] = ['title' => {intl l="All brands"}, 'url'=> '']}
    {/if}
{/if}
{/block}

{block name="main-content"}
{hook name="brand.top" brand="$brand_id"}
    {if $brand_id}
    <div class="main row">
        {$limit={$smarty.get.limit|default:8}}
        {$product_page={$smarty.get.page|default:1}}
        {$product_order={$smarty.get.order|default:'alpha'}}
        {$mode=$smarty.get.mode|default:'grid'}

        {hook name="brand.main-top" brand="$brand_id"}

        <article class="col-main col-md-9 col-md-push-3 {$mode}" role="main" aria-labelledby="main-label">

            {hook name="brand.content-top" brand="$brand_id"}

            {loop name="brand.info" type="brand" id=$brand_id limit="1"}
                <section class="brand-description">
                    <h1 id="main-label" class="page-header">{$TITLE}</h1>

                    {loop name="brand.image" type="image" source="brand" id={$LOGO_IMAGE_ID} width=218 height=146 resize_mode="borders"}
                        <p><img itemprop="image" src="{$IMAGE_URL nofilter}" alt="{$TITLE}"></p>
                    {/loop}

                    {if $CHAPO}
                        <div class="chapo">
                            {$CHAPO}
                        </div>
                    {/if}
                    {if $DESCRIPTION}
                        <div class="description">
                            {$DESCRIPTION nofilter}
                        </div>
                    {/if}
                    {if $POSTSCRIPTUM}
                        <small class="postscriptum">
                            {$POSTSCRIPTUM}
                        </small>
                    {/if}
                </section>

                {ifloop rel="product_list"}
                    <hr/>

                    {assign var="amount" value={count type="product" brand=$ID}}

                    {include file="includes/toolbar.html" toolbar="top" limit=$limit order=$product_order amount={$amount}}

                    <div id="category-products">
                        <div class="products-content">
                            <ul class="list-unstyled row">
                                {loop type="product" name="product_list" brand=$ID limit=$limit page=$product_page order=$product_order}
                                    {include file="includes/single-product.html" product_id=$ID hasBtn=true hasDescription=true hasQuickView=true width="218" height="146"}
                                {/loop}
                            </ul>
                        </div>
                    </div><!-- /#category-products -->

                    {include file="includes/toolbar.html" toolbar="bottom" amount={$amount}}
                {/ifloop}

                {elseloop rel="product_list"}
                    <div class="alert alert-warning">
                        {intl l="No products available in this brand"}
                    </div>
                {/elseloop}

                {hook name="brand.content-bottom" brand="$brand_id"}
            {/loop}
        </article>

        <aside class="col-left col-md-3 col-md-pull-9" role="complementary" itemscope itemtype="http://schema.org/WPSideBar">
            {include file="includes/brand-menu.html"}
        </aside>

        {hook name="brand.main-bottom" brand="$brand_id"}

    </div><!-- /.layout -->
    {else}
    <div class="main" id="brands">
        {hook name="brand.main-top"}
        <div class="col-main brands" role="main" aria-labelledby="main-label">
            {hook name="brand.content-top"}
            {ifloop rel="brands"}
            <ul class="list-unstyled">
                {loop name="brands" type="brand" with_prev_next_info="true"}
                <li class="item">
                    <article class="row">
                        <div class="brand-info col-sm-7">
                            {ifloop rel="brand_logo"}
                            <a href="{$URL nofilter}" tabindex="-1" class="brand-image overlay col-sm-2">
                                {loop name="brand_logo" type="image" source="brand" id={$LOGO_IMAGE_ID} width=218 height=146 resize_mode="borders" limit="1"}
                                <img src="{$IMAGE_URL nofilter}" class="img-responsive" alt="{$TITLE}">
                                {/loop}
                            </a>
                            {/ifloop}

                            <h2 class="name"><a href="{$URL nofilter}">{$TITLE}</a></h2>
                            {if $CHAPO}
                            <div class="short-description">
                                {$CHAPO}
                            </div>
                            {/if}
                        </div>
                    </article>
                </li>
                {/loop}
            </ul>
            {/ifloop}
            {elseloop rel="brand_logo"}

            {/elseloop}
            {hook name="brand.content-bottom"}
        </div>
        {hook name="brand.main-bottom"}
    </div>
    {/if}
    {hook name="brand.bottom" brand="$brand_id"}
{/block}

{block name="stylesheet"}
{hook name="brand.stylesheet"}
{/block}

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

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