{% unless settings.breadcrumb_styles == 'none' %}{% include 'breadcrumb' %}{% endunless %}

{% assign _lazyload = settings.use_lazyload %}
{% assign _layout = settings.general_placement %}
{% assign _catalog_sb_placement = section.settings.catalog_sb_placement %}

{% for block in section.blocks %}
  {% case block.type %}
    {% when 'filter' %}
      {% assign _filter_logic = block.settings.and_logic %}
  {% endcase %}
{% endfor %}

<div class="page-cata{% if _layout == 'wide' %} container-fluid{% endif %} sidebar-{{ section.settings.catalog_sb_placement }}{% if section.settings.sb_filters_position == 'body' %} sidebar-none{% endif %}" data-logic="{{ _filter_logic }}">
    <div class="row">
      
      {% if section.settings.catalog_sb_placement == 'left' %}
        {% include 'sidebar-catalog' %}
      {% endif %} 
      
      {% paginate collection.products by section.settings.item_per_page %}
      
      <div class="{% if section.settings.catalog_sb_placement == 'none' %}col-12{% else %}col-lg-9 col-md-12{% endif %}">
        
        {% if section.settings.col_des_position == 'top' and collection.description != blank %}
          <div class="cata-description">{{ collection.description }}</div>
        {% endif %}
        
        {% assign _collectionurl = '/collections/' | append: collection.handle %}
        
        {% unless section.settings.subcategory_menu == blank %}
          {% for _link in linklists[section.settings.subcategory_menu].links %} 
            {% assign _submenu = _link.title | handleize %}
            {% assign url = _link.url %}

            {% if linklists[_submenu].links.size > 0 and url == _collectionurl %}

              {% unless section.settings.subcategory_title == blank %}
                <h2 class="subcategory">{{ collection.title }} {{ section.settings.subcategory_title }}</h2>
              {% endunless %}

              <div class="subcategory-list">
                {% for link in linklists[_submenu].links %}

                  {% if link.type == 'collection_link' %}
                    {% assign _collection = link.object %}

                    <div class="category {{ _class }} text-center">
                      <div class="category-image">
                          <a href="{{ link.url }}">
                            {% assign image_size = '370x' %}
                            {% if _collection.image %}
                              <img src="{{ _collection | img_url: image_size }}" alt="{{ link.title | escape }}">
                            {% else %}
                            {% assign product = _collection.products.first %}
                              <img src="{{ product | img_url: image_size }}" alt="{{ link.title | escape }}">
                            {% endif %}
                          </a>
                      </div>
                      <a class="category-name" href="{{ link.url }}" title="{{ link.title | escape }}">{{ link.title }}</a>
                    </div>
                  {% endif %}

                {% endfor %}

              </div>

            {% endif %}

          {% endfor %}
        {% endunless %}

        <div class="wrap-cata-title">
          <h2>{{ collection.title }}</h2>
        </div>

        {% include 'cata-toolbar' %}
 
        
        {% for block in section.blocks %}
          {% case block.type%}
            {% when 'filter' %}
              {% include 'filter-body' %}
          {% endcase %} 
        {% endfor %}     
        
        
        <div id="col-main">
          {% if collection.products_count > 0 %}

            <div class="cata-product cp-grid{% if section.settings.catalog_sb_placement == 'none' %} no-sidebar{% endif %}">
              {% if collection.products.size > 0 %}

                {% for product in collection.products %}
                  <div class="product-grid-item mode-view-item" data-price="{{ product.price | divided_by: 100.00 | ceil }}">
                    {% include 'product-item' %}
                  </div>
                {% endfor %}

              {% endif %}
            </div>
          
          {% else %}
            <p>{{ 'collections.general.no_product' | t }}</p>
          
          {% endif %}
        </div>

        {% include 'pagination' %}
        
        {% if section.settings.col_des_position == 'bottom' and collection.description != blank %}
          <div class="cata-description">{{ collection.description }}</div>
        {% endif %}
      </div>
      
      {% endpaginate %}
      
      {% if section.settings.catalog_sb_placement == 'right' %}
        {% include 'sidebar-catalog' %}
      {% endif %}
      
    </div>
</div>

{% if settings.enable_notify_collection_page %}
  {% include 'layout-notify' %}
{% endif %}

{% schema %}
  {
    "name": "Collection pages",
    "settings": [
      {
        "type": "image_picker",
        "id": "breadcrumb_image",
        "label": "Breadcrumb image"
      },
      {
        "type": "select",
        "id": "col_des_position",
        "label": "Position of the collection description",
        "options": [
          {
            "value": "top",
            "label": "Top"
          },
          {
            "value": "bottom",
            "label": "Bottom"
          },
          {
            "value": "none",
            "label": "None"
          }
        ],
        "default": "top"
      },
      {
        "type": "checkbox",
        "id": "show_col_gl",
        "label": "Enable Mode View",
        "default": true
      },
      {
        "type": "checkbox",
        "id": "show_col_sort_by",
        "label": "Enable Sort by",
        "default": true
      },
      {
        "type": "text",
        "id": "item_per_page",
        "label": "Number of products per page",
        "default": "16"
      },
      {
        "type":"header",
        "content":"Sub Categories"
      },
      {
        "type":"link_list",
        "id":"subcategory_menu",
        "label":"Sub category menu",
        "info":"Please create a menu with each menu item is a collection."
      },
      {
        "type": "text",
        "id": "subcategory_title",
        "label": "Subcategory title",
        "default": "Categories"
      },


      {
        "type": "header",
        "content": "Collection Filter",
    "info": "To customize Collection Filter content, please click Add content."
      },
      {
        "type": "select",
        "id": "sb_filters_position",
        "label": "Filter position",
        "options": [
          { "value": "sidebar","label": "Sidebar" },
          { "value": "body","label": "Body" },
          { "value": "none","label": "None" }
        ],
        "default": "sidebar",
        "info":"Filter position 'Sidebar' does not work if Sidebar Placement is 'None'."
      },
      {
        "type": "select", 
        "id": "sb_filters_style",
        "label": "Filter sidebar style",
        "options": [
          { "value": "normal","label": "Normal" },
          { "value": "accordion","label": "Accordion" }
        ],
        "default": "normal"
      },
      {
        "type": "select",
        "id": "body_filters_style",
        "label": "Filter body and mobile style",
        "options": [
          { "value": "drawer","label": "Drawer" },
          { "value": "toggle","label": "Toggle" } 
        ],
        "default": "toggle"
      },
      
      {
        "type": "header",
        "content": "Sidebar Placement"
      },
      {
        "type": "select",
        "id": "catalog_sb_placement",
		"label": "Sidebar Placement",
        "options": [
          {
            "value": "left",
            "label": "Left"
          },
          {
            "value": "right",
            "label": "Right"
          },
          {
            "value": "none",
            "label": "None"
          }
        ],
        "info":"Go to 'Content' to add content to sidebar"
      }
    ], 
    "blocks":[
      {
        "type": "filter",
        "name": "Filter",
        "limit": 1,
        "settings": [
          {
            "type": "paragraph",
            "content": "To setup Filter by Groups like our demo, please add product's tag to format 'Group'_'Value'. For example: Color_Black, Brand_Elle"
          },
          {
            "type": "checkbox",
            "id": "and_logic",
            "label": "Disable 'AND' operator in a group filter",
            "default": true
          },
          {
            "type": "select",
            "id": "sb_filters",
            "label": "Filter type",
            "options": [
              {
                "value": "tags",
                "label": "Filter by Tags"
              },
              {
                "value": "groups",
                "label": "Filter by Groups"
              }
            ],
            "default": "groups"
          },
          {
            "type": "text",
            "id": "group_filter_prefix",
            "label": "Group use in filter",
            "default": "brand,color,price,size",
            "info": "Enter your tag's prefix,separate by comma ie: color,size,brand,price.."
          }
        ]
      },
      {
        "type": "categories",
        "name": "Sidebar-Categories",
        "limit": 1,
        "settings": [
          {
            "type":"paragraph",
            "content":"This does not work when Sidebar Placement is 'None'"
          },
          {
            "type": "text",
            "id": "sb_categories_title",
            "label": "Heading",
            "default": "#collection"
          },
          {
            "type": "select",
            "id": "sb_categories_type",
            "label": "Content Components",
            "options": [
              {
                "value": "categories",
                "label": "Categories"
              },
              {
                "value": "menu",
                "label": "Menu"
              },
              {
                "value": "none",
                "label": "None"
              }
            ],
            "default": "categories"
          },
          {
            "type": "link_list",
            "id": "sb_categories_menu",
            "label": "Menu item",
            "info": "Only for Content Component is Menu"
          },
          {
            "type": "text",
            "id": "sb_categories_limit",
            "label": "Total items",
            "default": "6",
            "info": "Only for Content Component is Categories"
          }
        ]
      },
      {
        "type": "banner",
        "name": "Sidebar-Banner",
        "settings": [
          {
            "type":"paragraph",
            "content":"This does not work when Sidebar Placement is 'None'"
          },
          {
            "type": "image_picker",
            "id": "sb_product_banner",
            "label": "Image",
            "info": "blank to hide"
          },
          {
            "type": "url",
            "id": "sb_product_banner_link",
            "label": "Link to"
          }
        ]
      },
      {
        "type": "product",
        "name": "Sidebar-Product",
        "settings": [
          {
            "type":"paragraph",
            "content":"This does not work when Sidebar Placement is 'None'"
          },
          {
            "type": "checkbox",
            "id": "enable_sb_latest_product",
            "label": "Enable sidebar latest products",
            "default": true
          },
          {
            "type": "text",
            "id": "sb_latest_product_title",
            "label": "Heading"
          },
          {
            "type": "collection",
            "id": "sb_latest_product_col",
            "label": "Collection"
          },
          {
            "type": "text",
            "id": "sb_latest_product_limit",
            "label": "Total items",
            "default": "8"
          }
        ]
      }
    ]
  }
{% endschema %}