{* @compiler:inline-only *}
{function cart_seller_row}
   <div class="seller-row {if $seller.is_ordering_disabled == 'Y'} disabled{/if}">
      <span class="custom-control-indicator"></span>
      <div class="content">
         <div>
            <p class="name">{$seller.title}</p>
            <span class="address">
               {$seller.city}, {$seller.street} {$seller.number}
               <span class="fc icons_copy" data-copy="{$seller.city}, {$seller.street} {$seller.number}"></span>
            </span>
         </div>
         <div class="seller-delivery-wrapper">
            {*            <a href="https://maps.google.com/?q={$seller.x},{$seller.y}" target="_blank" class="btn-link">{t}Zobrazit na mapě{/t}</a>*}
            <a href="https://maps.google.com/?q={$seller.title}" target="_blank" class="btn-link">{t}Zobrazit na mapě{/t}</a>

            {if $seller.availability == 2}
               <p class="delivery delivery-0">{t}Skladem - k vyzvednutí do dvou hodin{/t}</p>
            {else}
               <p class="delivery delivery-1">{t}K vyzvednutí do dvou dnů{/t}</p>
            {/if}
         </div>
         <div class="seller-opening-hours">
            {if $seller.data.display_opening_hours}
               {$opening_hours = []}
               {$opening_hours_parts = "\r\n"|explode:$seller.data.display_opening_hours}

               {if !$opening_hours_parts|count}
                  <p>{$seller.data.display_opening_hours|nl2br nofilter}</p>
               {else}
                  {foreach $opening_hours_parts as $part}
                     {$day_hour = "|"|explode:$part}
                     {$opening_hours[] = ['days' => $day_hour[0]|trim, 'hours' => $day_hour[1]|trim]}
                  {/foreach}
                  <table>
                     {foreach $opening_hours as $op}
                        <tr>
                           <td>{$op['days']}</td>
                           <td><strong>{$op['hours'] nofilter}</strong></td>
                        </tr>
                     {/foreach}
                  </table>
               {/if}
            {else}
               <table>
                  {$days = [
                  1 => "{t}Pondělí{/t}",
                  2 => "{t}Úterý{/t}",
                  3 => "{t}Středa{/t}",
                  4 => "{t}Čtvrtek{/t}",
                  5 => "{t}Pátek{/t}",
                  6 => "{t}Sobota{/t}",
                  7 => "{t}Neděle{/t}"
                  ]}
                  {for $i = 1 to 7}
                     <tr>
                        <td>{$days[$i]}:</td>
                        <td>
                           {if $seller.data['opening_hours'][$i][0]}
                              {$seller.data['opening_hours'][$i][0]} - {$seller.data['opening_hours'][$i][1]}
                           {else}
                              {t}zavřeno{/t}
                           {/if}
                        </td>
                     </tr>
                  {/for}
               </table>
            {/if}
         </div>
      </div>
      <label for="seller{$seller.id}" class="custom-control custom-radio btn btn-primary">{t}Zvolit prodejnu{/t}
         <input type="radio" name="{$deliveryPrefix}[seller_id]" value="{$seller.id}" id="seller{$seller.id}" class="custom-control-input" data-delivery-seller-input{if $info.id == $seller.id} checked{/if}>
      </label>
      <a href="https://maps.google.com/?q={$seller.x},{$seller.y}" target="_blank" class="btn-link link-responsive">{t}Zobrazit na mapě{/t}</a>
   </div>
{/function}

{block 'customization'}
   {$groupBy = 'data/city'}
{/block}

<div class="delivery-class" data-delivery-class="odbernaprodejne">
   {if $object.cart_description}
      {$object.cart_description nofilter}
   {/if}

   {$info = $object->getInfo($object.zip)}
   {if !$info.id}
      {get_active_seller assign='active_seller'}
      {$info = $object->getInfo($active_seller.id)}
   {/if}

   {get_sellers cart=1 groupBy=$groupBy assign='grouped_sellers'}

   <div data-reload="sellerpoint" class="posta-info open">
      {if !$info.id}
         {get_active_seller assign='active_seller'}
         {$info = $object->getInfo($active_seller.id)}
      {/if}
      {if $info.id}
         {get_sellers cart=1 assign="sellersAll"}
         {$selectedSeller = $sellersAll[$info.id]}

         <input type="hidden" name="delivery_seller_valid" value="1">
         <div class="ordering-selected-seller">
            <div class="content content-first">
               <div>
                  <p class="name">{$selectedSeller.title}</p>
                  <span class="address">
                     {$selectedSeller.city}, {$selectedSeller.street} {$selectedSeller.number}
                     <span class="fc icons_copy" data-copy="{$selectedSeller.city}, {$selectedSeller.street} {$selectedSeller.number}"></span>
                  </span>
               </div>
               <div class="seller-delivery-wrapper">
                  <a href="https://maps.google.com/?q={$selectedSeller.x},{$selectedSeller.y}" target="_blank" class="btn-link">{t}Zobrazit na mapě{/t}</a>

                  {if $selectedSeller.availability == 2}
                     <p class="delivery delivery-0">{t}Skladem - k vyzvednutí do dvou hodin{/t}</p>
                  {else}
                     <p class="delivery delivery-1">{t}K vyzvednutí do dvou dnů{/t}</p>
                  {/if}
               </div>
               <div class="change-seller-wrapper">
                  <a href="[data-ordering-sellers]" data-opener="[data-ordering-sellers]" class="btn btn-primary">{t}Změnit prodejnu{/t}</a>
               </div>
            </div>

            {get_seller id=$info.id assign='selected_seller'}
            <div class="content">
               <div>
                  {if $selected_seller.data.display_opening_hours}
                     {$opening_hours = []}
                     {$opening_hours_parts = "\r\n"|explode:$selected_seller.data.display_opening_hours}

                     {if !$opening_hours_parts|count}
                        <p>{$selected_seller.data.display_opening_hours|nl2br nofilter}</p>
                     {else}
                        {foreach $opening_hours_parts as $part}
                           {$day_hour = "|"|explode:$part}
                           {$hours = $day_hour[1]|trim}

                           {$opening_hours[] = ['days' => $day_hour[0]|trim, 'hours' => $hours]}
                        {/foreach}
                        <table class="selected-seller-opening-hours">
                           {foreach $opening_hours as $op}
                              <tr>
                                 <td>{$op['days']}</td>
                                 <td>{$op['hours']}</td>
                              </tr>
                           {/foreach}
                        </table>
                     {/if}
                  {else}
                     <table>
                        {$days = [
                        1 => "{t}Pondělí{/t}",
                        2 => "{t}Úterý{/t}",
                        3 => "{t}Středa{/t}",
                        4 => "{t}Čtvrtek{/t}",
                        5 => "{t}Pátek{/t}",
                        6 => "{t}Sobota{/t}",
                        7 => "{t}Neděle{/t}"
                        ]}
                        {for $i = 1 to 7}
                           <tr>
                              <td>{$days[$i]}:</td>
                              <td>
                                 {if $selected_seller.data['opening_hours'][$i][0]}
                                    {$selected_seller.data['opening_hours'][$i][0]|trim} - {$selected_seller.data['opening_hours'][$i][1]|trim}
                                 {else}
                                    {t}zavřeno{/t}
                                 {/if}
                              </td>
                           </tr>
                        {/for}
                     </table>
                  {/if}
               </div>
               <div class="content-contact">
                  <p>
                     {$selected_seller.phone}<br>
                     <a href="mailto:{$selected_seller.email}">{$selected_seller.email}</a>
                  </p>
               </div>
            </div>
            <div class="change-seller-wrapper">
               <a href="[data-ordering-sellers]" data-opener="[data-ordering-sellers]" class="btn btn-primary">{t}Změnit prodejnu{/t}</a>
            </div>
            <a href="https://maps.google.com/?q={$seller.x},{$seller.y}" target="_blank" class="btn-link link-responsive">{t}Zobrazit na mapě{/t}</a>
         </div>
      {/if}
   </div>

   <div class="ordering-sellers" {if $info.id}style="display:none;"{/if} data-ordering-sellers="ordering">
      <div class="seller-search">
         <div class="form-group">
            <input type="text" class="form-control" placeholder="{t}Zadejte město, PSČ nebo ulici{/t}" data-seller-search-input="ordering">
            <i class="fc icons_search"></i>
         </div>
      </div>
      <div class="sellers-list">
         <div class="sellers-list-inner sellers-search-list" data-seller-list="ordering">
            {foreach $grouped_sellers as $city => $sellers}
               {$city_instore = false}
               {$city_instore_count = 0}
               {foreach $sellers as $seller}
                  {if $seller.availability == 2}
                     {$city_instore = true}
                     {$city_instore_count = $city_instore_count + 1}
                  {/if}
               {/foreach}
               <div class="region-row{if $city@last} last{/if}" data-custom-opener="[data-sellers-{$city|strip_accent}-ordering]">
                  <p class="title">{$city}</p>
                  <span class="count{if $city_instore} has-pieces{/if}">{if $city_instore}{t pocet=$city_instore_count count=$city_instore_count}Skladem na {pocet} prodejně z{/t} {count($sellers)}{else} {count($sellers)} {t count=count($sellers)}prodejna{/t}{/if}</span>
               </div>
               <div class="region-sellers" data-sellers-{$city|strip_accent}-ordering>
                  {foreach $sellers as $seller}
                     {cart_seller_row}
                  {/foreach}
               </div>
            {/foreach}

            <div class="seller-not-found" data-seller-not-found="ordering" style="display: none;">
               <p>{t}Nenalezena žádná prodejna.{/t}</p>
            </div>
         </div>
      </div>
   </div>
</div>
