{{ 'section-featured-collection-with-image.aio.min.css' | asset_url | stylesheet_tag }}

{%- liquid
  assign section_id = '#section-' | append: section.id
  assign slider_id = '#slider-' | append: section.id
  assign controls_id = '#controls-' | append: section.id
  assign items_resp = section.settings.items_resp
  assign image = section.settings.image

  assign collection = collections[section.settings.collection]
  if section.settings.collection != blank and section.settings.limit > collection.all_products_count
    assign limit = collection.all_products_count
  else
    assign limit = section.settings.limit
  endif

  if image == blank
    if section.settings.collection == blank or collection.all_products_count < 1
      assign col_class = 'col-lg-6'
    else
      assign col_class = 'col-lg-12'
    endif
  else
    assign col_class = 'col-lg-6'
  endif

  if section.settings.border_radius != 'none'
    assign bg_class = ' .section-wrapper'
  else
    assign bg_class = ''
  endif

  assign heading_style_block = section.blocks | where: 'type' , 'heading-style' | first
-%}

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



<div class="section-featured-collection-with-image border-radius-{{ section.settings.border_radius }}" id="section-{{ section.id }}" data-section-id="{{ section.id }}" data-section-type="featured-collection">
  <div class="{%- if template == 'index' or template contains 'page' -%}{{ section.settings.section_layout }}{%- endif -%}">
    <div class="section-wrapper">
      <div class="row row-item">

        {%- if section.settings.collection == blank and image == blank -%}
          <div class="block-image col-lg-6 col-12">
            <div class="block-image-inner">
              {{ 'hero-apparel-1' | placeholder_svg_tag: 'placeholder-svg' }}
            </div>
          </div>
        {%- endif -%}

        {%- if image and section.settings.position == 'left' -%}
          <div class="block-image col-lg-6 col-12">
            <div class="block-image-inner">
              <a href="{{ section.settings.link | default: 'javascript:void(0)' }}">
                {%- render 'image-style', image: image, limit: 768 -%}
              </a>
            </div>
          </div>
        {%- endif -%}

        <div class="section-body {{ col_class }} col-12">
          {%- 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="block-slider-component">
            <slider-component>
              <div class="slider-container js-slider-container">
                <div class="slider-wrapper">
                  <div class="slider-list" id="slider-{{ section.id }}">
                    {{ content }}
                  </div>

                  {%- 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,
                    items_resp: items_resp,
                    total_item: limit
                  -%}
                </div>
              </div>
            </slider-component>
          </div> 
        </div>

        {%- if image and section.settings.position == 'right' -%}
          <div class="block-image col-lg-6 col-12">
            <div class="block-image-inner">
              <a href="{{ section.settings.link | default: 'javascript:void(0)' }}">
                {%- render 'image-style', image: image, limit: 768 -%}
              </a>
            </div>
          </div>
        {%- endif -%}

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

<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>

{%- 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.featured-collection-with-image.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": "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": "select",
      "id": "border_radius",
      "label": "t:sections.featured-collection.settings.corner_radius.label",
      "default": "none",
      "options": [
        {
          "value": "top",
          "label": "Top"
        },
        {
          "value": "bottom",
          "label": "Bottom"
        },
        {
          "value": "none",
          "label": "None"
        }
      ]
    },
    {
      "type": "header",
      "content": "t:sections.common.block_product"
    },
    {
      "type": "text",
      "id": "heading",
      "label": "t:sections.common.heading",
      "default": "Featured products"
    },
    {
      "type": "inline_richtext",
      "id": "subheading",
      "label": "t:sections.common.subtext"
    },
    {
      "type": "collection",
      "id": "collection",
      "label": "t:sections.common.collection"
    },
    {
      "type": "text",
      "id": "items_resp",
      "label": "t:sections.common.items_per_row",
      "default": "3,2"
    },
    {
      "type": "range",
      "id": "limit",
      "label": "t:sections.common.limit",
      "step": 1,
      "min": 1,
      "max": 8,
      "default": 6
    },
    {
      "type": "header",
      "content": "t:sections.common.block_image"
    },
    {
      "type": "select",
      "id": "position",
      "label": "t:sections.common.position",
      "default": "left",
      "options": [
        { "value": "left", "label": "t:sections.common.left" },
        { "value": "right", "label": "t:sections.common.right" }
      ]
    },
    {
      "type": "image_picker",
      "id": "image",
      "label": "t:sections.common.image"
    },
    {
      "type": "url",
      "id": "link",
      "label": "t:sections.common.link",
      "default": "/"
    },
    {
      "type": "header",
      "content": "t:sections.common.slider_settings"
    },
    {
      "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": "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
        }
      ]
    }
  ],
  "presets": [
    {
      "name": "t:sections.featured-collection-with-image.name"
    }
  ]
}
{%- endschema -%}