import{makeStyle as e,template as t}from"@gem-sdk/core";import{getDynamicSourceLocales as a,createSettingId as r}from"../../../../helpers.js";import{customClass as i}from"./classes.js";import s from"html-react-parser";import{createClass as o,createStyle as n}from"@gem-sdk/system";import{getCustomStyle as l,getPaginatorStyle as m}from"./styles.js";import{CollectionPaginator as p}from"../../../settings/collection-paginator/configs/translate.js";let renderPaginatorItem=({setting:e,builderProps:t,pageContext:a},r)=>"liquid"===r?renderPaginatorLive({setting:e,builderProps:t,pageContext:a}):renderPaginatorEditor({setting:e,builderProps:t,pageContext:a}),renderPaginatorLive=({setting:e,builderProps:t,pageContext:a})=>{let r=getPreviousTextVal({setting:e,builderProps:t,pageContext:a},"liquid"),i=getNextTextVal({setting:e,builderProps:t,pageContext:a},"liquid"),s=e?.numberOfProducts||a?.numberOfProductOfProductList||0,o=s>0?s:4,n=e=>e?.replace(/"/g,'\\"')??"",l=`"${n(r??"")}"`,m=`"${n(i??"")}"`;return`
    {% paginate collection.products by ${o} %}
      {% assign previousText = ${a?.isPreviewing?l:r||'""'} %}
      {% assign nextText = ${a?.isPreviewing?m:i||'""'} %}

      {{ paginate | default_pagination: previous: previousText, next: nextText }}
    {% endpaginate %}
  `},renderPaginatorEditor=({setting:t,builderProps:a,pageContext:r})=>{let{pageQuantity:p,typo:g,normalColor:c,activeColor:u}=t??{},d=[],x=parseInt(p??"0"),P=6;6>x&&(P=x-1);let y=P>1?P-1:0,f=getPreviousTextVal({setting:t,builderProps:a,pageContext:r},"react"),v=getNextTextVal({setting:t,builderProps:a,pageContext:r},"react"),I=o({...i("prev",c,t)}),T=o({...i("page",c,t)}),h=o({...i("deco",c,t)}),N=e=>o({...i("page",e===y?u:c,t)}),k=o({...i("deco",c,t)}),L=o({...i("page",c,t)}),$=o({...i("next",c,t)}),q=e=>n({...m(e===y,l(t),u)}),w=n({...l(t),...e({w:"auto"})}),z=n({...l(t)}),C=n({...l(t),...e({w:"auto"})});y>0&&d.push(createPaginatorItem({key:"prev",text:g?.attrs?.transform==="capitalize"?f?.toLocaleLowerCase():f,className:I,style:w})),y>2&&d.push(createPaginatorItem({key:1,text:1,className:T,style:z})),y>3&&d.push(createPaginatorItem({key:"deco",text:"...",className:h,style:z}));for(let e=Math.max(0,y-2);e<=Math.min(y+2,x-1);e++)d.push(createPaginatorItem({key:e+1,text:e+1,className:N(e),style:q(e)}));return y<x-4&&d.push(createPaginatorItem({key:"deco-2",text:"...",className:k,style:z})),y<x-3&&d.push(createPaginatorItem({key:x,text:x,className:L,style:z})),y!==x-1&&0!==x&&d.push(createPaginatorItem({key:"next",text:g?.attrs?.transform==="capitalize"?v?.toLocaleLowerCase():v,className:$,style:C})),d.map(e=>s(e))},createPaginatorItem=({key:e,text:a,className:r,style:i})=>t`<span key="${e}" className="${r}" style="${i}"> ${a} </span>`,getPreviousTextVal=({setting:e,builderProps:t,pageContext:i},s)=>{let{previousText:o,typo:n}=e??{};return"liquid"===s?a({val:o,uid:t?.uid,settingId:r({id:p?.previousText?.id}),pageContext:i??{},isLiquid:!0,isCapitalize:n?.attrs?.transform==="capitalize"}).toString():o},getNextTextVal=({setting:e,builderProps:t,pageContext:i},s)=>{let{nextText:o,typo:n}=e??{};return"liquid"===s?a({val:o,uid:t?.uid,settingId:r({id:p?.nextText?.id}),pageContext:i??{},isLiquid:!0,isCapitalize:n?.attrs?.transform==="capitalize"}).toString():o};export{renderPaginatorItem};
