{{ 'section-single-product.aio.min.css' | asset_url | stylesheet_tag }}

{%- liquid
  assign bg_image = section.settings.bg_image
  assign section_id = '#section-' | append: section.id
  assign slider_id = '#slider-' | append: section.id
  assign controls_id = '#controls-' | append: section.id
  assign enable_slider =section.settings.enable_slider
  assign items_spacing = section.settings.items_spacing
  assign heading_style_block = section.blocks | where: 'type' , 'heading-style' | first
  assign gallery_blocks = section.blocks | where: 'type', 'product'
  assign limit = gallery_blocks.size

  assign style = section.settings.style
  if style == 3 or style == 4
    assign items_resp = section.settings.items_resp
    
    if items_spacing
      assign items_spacing_slider = '30px'
    else
      assign items_spacing_slider = '0'
    endif

    if items_spacing == false and enable_slider == false
      assign items_spacing_row = 'no-padding'
    endif

  else
    assign items_resp = '1'
    if enable_slider
      assign items_spacing_slider = '0'
    else
      assign items_spacing_row = 'no-padding'
    endif
  endif
-%}

{%- if section.settings.section_layout == 'container-fluid' -%}
  {%- assign bg_class = '' -%}
  {%- assign full_width = 'full-width' -%}
  {%- capture bg_wide -%}{%- render 'bg_responsive', image_desk: bg_image, image_mobi: bg_image -%}{%- endcapture -%}
{%- else -%}
  {%- assign bg_class = ' .section-wrapper' -%}
  {%- capture bg_boxed -%}{%- render 'bg_responsive', image_desk: bg_image, image_mobi: bg_image -%}{%- endcapture -%}
{%- endif -%}

{%- capture section_heading -%}
  {%- render 'snippet-heading', type:'render-html', config: section.settings -%}
{%- endcapture -%}

{%- capture grid_class -%}{%- render 'set-item-per-row', value: items_resp -%}{%- endcapture -%}

<div class="section-single-product {{ full_width }} {{ bg_wide }}" id="section-{{ section.id }}" data-section-id="{{ section.id }}"{% if enable_slider %} data-section-type="featured-collection"{% endif %}>
  <div class="container">
    <div class="section-wrapper {{ bg_boxed }} {{ items_spacing_row }}">

      {%- if section_heading != blank -%}
        {%- capture heading_css -%}
          {%- render 'snippet-heading', type: 'render-css', config: heading_style_block.settings, classID: section_id -%}
        {%- endcapture -%}
        <div class="section-header">{{ section_heading }}</div>
      {%- endif -%}

      <div class="section-body single-product-list style-{{ style }}">
        <slider-component>
          <div class="slider-container js-slider-container">
            <div class="slider-wrapper">
              <div class="slider-list{% unless enable_slider %} row{% endunless %}" id="slider-{{ section.id }}">
                {%- for block in gallery_blocks -%}
                  {%- assign product = all_products[block.settings.product] -%}
                  <div class="slider-item{% unless enable_slider %} {{ grid_class }}{% endunless %}">
                    {%- render 'single-product-item', product: product, block: block, style: style -%}
                  </div>
                {%- endfor -%}
              </div>

              {%- if enable_slider -%}
                {%- render 'set-tns-config'
                  slider_id: slider_id,
                  classID: section_id,
                  loop: section.settings.loop,
                  dots: section.settings.dots,
                  controls: section.settings.controls,
                  controls_id: controls_id,
                  customControls: true,
                  autoplay: section.settings.autoplay,
                  autoplay_timeout: section.settings.autoplay_timeout,
                  padding: items_spacing_slider,
                  items_resp: items_resp,
                  total_item: limit
                -%}
              {%- endif -%}
            </div>
          </div>
        </slider-component>
      </div>
    </div>
  </div>
</div>

{%- if enable_slider -%}
  <script>
    window.theme = window.theme || {};
    if(!!window.theme.sectionRegister){
      !window.theme.sectionRegister.includes("featured-collection") && (window.theme.sectionRegister = [...window.theme.sectionRegister, "featured-collection"]);
    }else{
      window.theme.sectionRegister = ["featured-collection"];
    }
  </script>

  <script>
    window.theme = window.theme || {};
    if(!!window.theme.customElementsList){
      !window.theme.customElementsList.includes("slider-component") && (window.theme.customElementsList = [...window.theme.customElementsList, "slider-component"]);
    }else{
      window.theme.customElementsList = ["slider-component"];
    }
  </script>
{%- endif -%}

{%- capture section_css -%}
  {{- heading_css -}}
  {%- render 'snippet-theme', type: 'section-style', preClassID: section_id, classID: bg_class, config: section.settings -%}
{%- endcapture -%}

{%- style -%}{{ section_css | strip | strip_newlines | remove: '  ' }}{%- endstyle -%}

{%- schema -%}
{
  "name": "t:sections.single-product.name",
  "tag": "section",
  "disabled_on": {
    "groups": ["header", "footer"]
  },
  "settings": [
    {
      "type": "select",
      "id": "section_layout",
      "label": "t:settings_schema.global.settings.layout_mode.label",
      "default": "container",
      "options": [
        {
          "value": "container",
          "label": "t:settings_schema.global.settings.layout_mode.options__1.label"
        },
        {
          "value": "container-fluid",
          "label": "t:settings_schema.global.settings.layout_mode.options__2.label"
        }
      ]
    },
    {
      "type": "range",
      "id": "style",
      "label": "t:sections.common.style",
      "default": 1,
      "min": 1,
      "max": 4
    },
    {
      "type": "text",
      "id": "margin",
      "label": "t:sections.common.section_margin",
      "info": "t:sections.common.order_info"
    },
    {
      "type": "text",
      "id": "padding",
      "label": "t:sections.common.section_padding",
      "info": "t:sections.common.order_info"
    },
    {
      "type": "color",
      "id": "bg_color",
      "label": "t:sections.common.background_color"
    },
    {
      "type": "image_picker",
      "id": "bg_image",
      "label": "t:sections.common.background_image"
    },
    {
      "type": "text",
      "id": "heading",
      "label": "t:sections.common.heading",
      "default": "Featured products"
    },
    {
      "type": "text",
      "id": "items_resp",
      "label": "t:sections.common.items_per_row",
      "default": "2,1",
      "info": "t:sections.single-product.settings.only_style_3"
    },
    {
      "type": "checkbox",
      "id": "items_spacing",
      "label": "t:sections.common.items_spacing",
      "default": true,
      "info": "t:sections.single-product.settings.only_style_3"
    },
    {
      "type": "header",
      "content": "t:sections.common.slider_settings"
    },
    {
      "type": "checkbox",
      "id": "enable_slider",
      "label": "t:sections.common.enable_slider",
      "default": true
    },
    {
      "type": "checkbox",
      "id": "loop",
      "label": "t:sections.common.loop",
      "default": false
    },
    {
      "type": "checkbox",
      "id": "controls",
      "label": "t:sections.common.controls",
      "default": true
    },
    {
      "type": "checkbox",
      "id": "dots",
      "label": "t:sections.common.dots",
      "default": true
    },
    {
      "type": "checkbox",
      "id": "autoplay",
      "label": "t:sections.common.autoplay",
      "default": false
    },
    {
      "type": "range",
      "id": "autoplay_timeout",
      "label": "t:sections.common.autoplay_timeout",
      "step": 0.1,
      "min": 2,
      "max": 10,
      "unit": "s",
      "default": 4
    }
  ],
  "blocks": [
    {
      "type": "heading-style",
      "limit": 1,
      "name": "t:sections.common.heading_style",
      "settings": [
        {
          "type": "select",
          "id": "section_heading_container_align",
          "label": "t:sections.common.alignment",
          "options": [
            {
              "value": "start",
              "label": "t:sections.common.left"
            },
            {
              "value": "center",
              "label": "t:sections.common.center"
            },
            {
              "value": "end",
              "label": "t:sections.common.right"
            }
          ]
        },
        {
          "type": "text",
          "id": "section_heading_margin",
          "label": "t:sections.common.margin",
          "info": "t:sections.common.order_info"
        },
        {
          "type": "color",
          "id": "section_heading_color",
          "label": "t:sections.common.text_color"
        },
        {
          "type": "text",
          "id": "section_heading_font_size",
          "label": "t:sections.common.font_size",
          "info": "t:sections.common.unit_px"
        },
        {
          "type": "range",
          "id": "section_heading_font_weight",
          "label": "t:sections.common.font_weight",
          "step": 100,
          "min": 100,
          "max": 900,
          "default": 600
        }
      ]
    },
    {
      "type": "product",
      "name": "t:sections.common.block_item",
      "limit": 6,
      "settings": [
        {
          "type": "product",
          "id": "product",
          "label": "t:sections.common.product"
        },
        {
          "type": "header",
          "content": "t:sections.common.textbox",
          "info": "t:sections.single-product.settings.only_style_1"
        },
        {
          "type": "image_picker",
          "id": "image",
          "label": "t:sections.common.image"
        },
        {
          "type": "color",
          "id": "text_color",
          "label": "t:sections.common.text_color",
          "default": "#000000"
        },
        {
          "type": "text",
          "id": "text_1",
          "label": "t:sections.common.text",
          "default": "LIMITED"
        },
        {
          "type": "text",
          "id": "text_2",
          "label": "t:sections.common.subtext",
          "default": "WEEK DEAL"
        },
        {
          "type": "textarea",
          "id": "text_3",
          "label": "t:sections.common.subtext_2",
          "default": "HURRY UP BEFORE OFFER WILL END"
        },
        {
          "id": "buy_now",
          "type": "text",
          "label": "t:sections.common.button_label",
          "default": "BUY NOW"
        }
      ]
    }
  ],
  "presets": [
    {
      "name": "t:sections.single-product.name",
      "blocks": [
        {
          "type": "product"
        },
        {
          "type": "product"
        }
      ]
    }
  ]
}
{%- endschema -%}