"use strict";var e=require("@gem-sdk/core"),t=require("../../helpers.js"),r=require("../../link/components/Link.js"),l=require("../../constant.js"),s=require("./styles.js"),o=require("../settings/configs/translate.js");const i=(e,t)=>{if(!t)return e;let r={...e};return["hover","focus"].forEach(e=>{delete r?.backgroundColorV2?.[e]}),r},a=({label:r,translateSetting:l,styles:s,pageContext:i,isUseTranslatedValue:a,builderProps:n,isLiquid:p=!1,isForceValue:c})=>{let g=!a||c?r:t.getDynamicSourceLocales({val:r,pageContext:i,settingId:t.createSettingId({id:l??o.Button?.label?.id}),uid:n?.uidTranslate??n?.uid,isCapitalize:s?.typo?.attrs?.transform==="capitalize"});return p?g?.toString()??"":e.convertHTML(r)},n=(e,t)=>!!e&&t,p=(e,t)=>!!e||!t,c=({mode:e,options:t,isLiquid:r=!1})=>r?!t?.isCannotEditing:"edit"===e&&!t?.isCannotEditing,g=e=>!!e?.link?.startsWith("#")&&("_self"===e.target||"scroll-to"===e.type),u=t=>e.splitStyle(["pos","top","left","bottom","right","z"],t),d=e=>e?"loading":"idle",h=(e,t,r)=>e??(t||r)??"",f=({label:e,isLiquid:t=!1})=>t?e?.toString().replaceAll("'","&#039;").replaceAll('"',"'")??"":e?.toString()??"",S=`
  <svg
    class="gp-invisible gp-absolute gp-h-5 gp-w-5 group-data-[state=loading]:gp-animate-spin group-data-[state=loading]:gp-visible"
    xmlns="http://www.w3.org/2000/svg"
    fill="none"
    viewBox="0 0 24 24"
  >
    <circle
      class="gp-opacity-25"
      cx="12"
      cy="12"
      r="10"
      stroke="currentColor"
      stroke-width="4"
    ></circle>
    <path
      class="gp-opacity-75"
      fill="currentColor"
      d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
    ></path>
  </svg>
`;exports.LOADING_INDICATOR=S,exports.checkIsScrollToElement=g,exports.checkIsShowIcon=n,exports.getCleanedStyles=i,exports.getData=e=>{let{style:t,dataId:r,pageContext:l,styles:o={},setting:S={},builderProps:k,builderAttrs:x,isUseTranslatedValue:y=!0}=e,{label:C,iconSvg:I,btnLink:b,loading:m,options:L,disabled:w,iconVisible:v,shouldClearSpace:E}=S,[T,A]=u(t),D=i(o,w),q=s.getCustomCssStyles({styles:o,uid:k?.uid,builderAttrs:x,enableHoverEffect:S.enableHoverEffect??!0}),_=d(m),j=h(k?.uidInteraction,r,k?.uid),z=e=>{let{isLiquid:t,translateSetting:r,isForceValue:s,pageContext:o}=e??{};return a({pageContext:o??l??{},label:C,translateSetting:r,isForceValue:s,builderProps:k,styles:D,isLiquid:t,...t&&{isUseTranslatedValue:y}})},H=n(I,v),O=g(b);return{customCss:q,wrapStyle:T,restStyle:A,dataState:_,dataIdAttr:j,isShowIcon:H,isScrollToElement:O,getArialLabel:e=>{let{isLiquid:t}=e??{};return f({label:C,isLiquid:t})},getLabelToDisplay:z,checkIsShowLabel:e=>{let{isLiquid:t,translateSetting:r,isForceValue:s,pageContext:o}=e??{},i=z({isLiquid:t,translateSetting:r,isForceValue:s,pageContext:o??l??{}});return p(i,E)},checkIsEditableLabel:e=>{let{isLiquid:t,mode:r}=e??{};return c({options:L,isLiquid:t,...!t&&r&&{mode:r}})}}},exports.getDataId=h,exports.getDataState=d,exports.getInsertLinkData=({setting:e,htmlType:s,defaultTag:o,enableBtnLink:i,isLiquid:a=!1,pageType:n})=>{let p=["product.url"],c=["#","mailto:","tel:"],g=e?.link??"",u="/"===g,d=e?.link!==void 0&&""!==e.link,h=new RegExp(/^https?:\/\//i),f=d&&h.test(g);d&&g.toLowerCase().startsWith("mailto:")&&g.includes("+")&&(g=t.normalizeMailto(g));let S=t.isLinkedToSalesPage(e?.type),k=!!i&&(f||t.isShopifyDomain(d,g)||(()=>{if(p.find(e=>g.includes(e)))return!0;let r=c.find(e=>g.startsWith(e));return!(!r||t.checkIsScrollToTop(e)||"STATIC"===n&&t.checkIsOpenPopup(e))})()||u||S),x=g;a&&(t.isShopifyDomain(d,g)||u)&&(x=e?.isTranslate?"$locationOrigin"+g:"{{ request.origin }}{{ routes.root_url | split: '/' | join: '/' }}"+g);let y=k?a?"a":r.default:o,C={href:x,target:e?.target,...e?.noFollow&&{rel:"nofollow"}},I=k?C:d?{...C,type:s}:{type:s};return S&&(I={href:l.HREF_TO_SALES_PAGE,target:"_self"}),{HTMLTag:y,urlData:I,shouldRenderLink:k}},exports.getSplitStyles=u,exports.handleCheckIsEditableLabel=c,exports.handleCheckIsShowLabel=p,exports.handleGetArialLabel=f,exports.handleGetLabelToDisplay=a;
