import{template as o,RenderIf as s,isLocalEnv as t,baseAssetURL as e}from"@gem-sdk/core";import{getSettingPreloadData as l}from"../../../helpers.js";import{createClass as i,createStyle as n,createStateOrContext as r,LiquidIf as c}from"@gem-sdk/system";import{getClassContainer as a,getClassToolbarWrapper as p,getClassToolbarSortWrapper as d,getClassSelect as m,getClassToolbarWrapperQuantity as u}from"./common/classes.js";import{getStyleCollectionToolbar as f,getStyleToolbarWrapper as $,getStyleSelect as y,getStyleToolbarWrapperQuantity as g}from"./common/styles.js";import{getSortingTextDisplayVal as v,getQuantityTextDisplayVal as b}from"./common/helpers.js";let CollectionToolbar=({setting:_,builderProps:S,pageContext:j})=>{let{displayQuantity:k}=_??{},q=i({...a()}),T=i({...p()}),C=i({...d()}),E=i({...m(_)}),h=i({...u(_)}),x=i({"gp-flex-1":!0}),A=n({...f(_)}),G=n({...$(_)}),N=n({...y(_)}),O=n({...g(_)}),I=v({setting:_,builderProps:S,pageContext:j},"liquid"),J=b({setting:_,builderProps:S,pageContext:j},"liquid"),M=r({uid:S?.uid});return o`
    <gp-collection-toolbar
      class="${q}"
      style="${A}"
      id="${S?.uid}"
      gp-data='${JSON.stringify(M)}'
    >
      <div class="${T}" style="${G}" >
        <div class="${C}">
          <select id="sorting" class="${E}" style="${N}" >

            {% if collection.sort_by == "" %}
              {% assign sort_by = collection.default_sort_by %}
            {% else %}
              {% assign sort_by = collection.sort_by %}
            {% endif %}

            <option key=${I} value="">
              ${I}
            </option>
            {% for option in collection.sort_options %}
              {% if sort_by == option.value %}
                <option value="{{ option.value }}" selected>{{ option.name }}</option>
              {% else %}
                <option value="{{ option.value }}">{{ option.name }}</option>
              {% endif %}
            {% endfor %}
          </select>
        </div>
        <div
          class="${h}"
          style="${O}"
        >
          {% assign quantityTemplate = ${J} %}
          {% assign productsCount = collection.products_count %}
          ${c(k?.toString()??"",o`<span class="gf_product-quantity">{{ quantityTemplate | replace: '%number%', productsCount }}</span>`,"")}
        </div>
        <div class="${x}">&nbsp;</div>
      </div>
    </gp-collection-toolbar>
    ${s(t,`<script ${l('class="gps-link" delay',"src")}="{{ 'gp-collection-toolbar-v7-5.js' | asset_url }}" defer="defer"></script>`,`<script ${l('class="gps-link" delay',"src")}="${e}/assets-v2/gp-collection-toolbar-v7-5.js?v={{ shop.metafields.GEMPAGES.ASSETS_VERSION }}" defer="defer"></script>`)}
  `};export{CollectionToolbar as default};
