"use strict";var core=require("@gem-sdk/core"),helpers=require("../../helpers.js"),Link=require("../../link/components/Link.js"),constant=require("../../constant.js"),styles=require("./styles.js");const getCleanedStyles=(e,t)=>{if(!t)return e;let l={...e},a=["hover","focus"];return a.forEach(e=>{delete l?.backgroundColorV2?.[e]}),l},handleGetLabelToDisplay=({label:e,styles:t,translate:l,pageContext:a,isUseTranslatedValue:s,builderProps:r,isLiquid:o=!1})=>{let i=s?helpers.getDynamicSourceLocales({translate:l,val:e,pageContext:a,settingId:l??"label",uid:r?.uidTranslate??r?.uid,isCapitalize:t?.typo?.attrs?.transform==="capitalize"}):e;return o?i?.toString()??"":core.convertHTML(e)},checkIsShowIcon=(e,t)=>!!e&&t,handleCheckIsShowLabel=(e,t)=>!!e||!t,handleCheckIsEditableLabel=({mode:e,options:t,isLiquid:l=!1})=>l?!t?.isCannotEditing:"edit"===e&&!t?.isCannotEditing,checkIsScrollToElement=e=>!!e?.link?.startsWith("#")&&("_self"===e.target||"scroll-to"===e.type),getSplitStyles=e=>core.splitStyle(["pos","top","left","bottom","right","z"],e),getDataState=e=>e?"loading":"idle",getDataId=(e,t,l)=>e??(t||l)??"",handleGetArialLabel=({label:e,isLiquid:t=!1})=>t?e?.toString().replaceAll("'","&#039;").replaceAll('"',"'")??"":e?.toString()??"",getInsertLinkData=({setting:e,htmlType:t,defaultTag:l,enableBtnLink:a,isLiquid:s=!1,pageType:r})=>{let o=["product.url"],i=["#","mailto:","tel:"],n=e?.link??"",c="/"===n,p=e?.link!==void 0&&""!==e.link,h=new RegExp(/^https?:\/\//i),d=p&&h.test(n);p&&n.toLowerCase().startsWith("mailto:")&&n.includes("+")&&(n=helpers.normalizeMailto(n));let g=()=>{if(o.find(e=>n.includes(e)))return!0;let t=i.find(e=>n.startsWith(e));return!(!t||helpers.checkIsScrollToTop(e)||"STATIC"===r&&helpers.checkIsOpenPopup(e))},u=helpers.isLinkedToSalesPage(e?.type),I=!!a&&(d||helpers.isShopifyDomain(p,n)||g()||c||u),S=n;s&&(helpers.isShopifyDomain(p,n)||c)&&(S=e?.isTranslate?"$locationOrigin"+n:"{{ request.origin }}{{ routes.root_url | split: '/' | join: '/' }}"+n);let k=I?s?"a":Link.default:l,y={href:S,target:e?.target,...e?.noFollow&&{rel:"nofollow"}},L=I?y:p?{...y,type:t}:{type:t};return u&&(L={href:constant.HREF_TO_SALES_PAGE,target:"_self"}),{HTMLTag:k,urlData:L,shouldRenderLink:I}},getData=e=>{let{style:t,dataId:l,pageContext:a,styles:s={},setting:r={},builderProps:o,builderAttrs:i,isUseTranslatedValue:n=!0}=e,{label:c,iconSvg:p,btnLink:h,loading:d,options:g,disabled:u,translate:I,iconVisible:S,shouldClearSpace:k}=r,[y,L]=getSplitStyles(t),b=getCleanedStyles(s,u),D=styles.getCustomCssStyles({styles:s,uid:o?.uid,builderAttrs:i,enableHoverEffect:r.enableHoverEffect??!0}),C=getDataState(d),f=getDataId(o?.uidInteraction,l,o?.uid),T=e=>{let{isLiquid:t}=e??{};return handleGetArialLabel({label:c,isLiquid:t})},w=e=>{let{isLiquid:t}=e??{};return handleGetLabelToDisplay({label:c,builderProps:o,styles:b,isLiquid:t,...t&&{translate:I},...t&&{pageContext:a},...t&&{isUseTranslatedValue:n}})},m=e=>{let{isLiquid:t}=e??{},l=w({isLiquid:t});return handleCheckIsShowLabel(l,k)},x=e=>{let{isLiquid:t,mode:l}=e??{};return handleCheckIsEditableLabel({options:g,isLiquid:t,...!t&&l&&{mode:l}})},E=checkIsShowIcon(p,S),A=checkIsScrollToElement(h);return{customCss:D,wrapStyle:y,restStyle:L,dataState:C,dataIdAttr:f,isShowIcon:E,isScrollToElement:A,getArialLabel:T,getLabelToDisplay:w,checkIsShowLabel:m,checkIsEditableLabel:x}},LOADING_INDICATOR=`
  <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=LOADING_INDICATOR,exports.checkIsScrollToElement=checkIsScrollToElement,exports.checkIsShowIcon=checkIsShowIcon,exports.getCleanedStyles=getCleanedStyles,exports.getData=getData,exports.getDataId=getDataId,exports.getDataState=getDataState,exports.getInsertLinkData=getInsertLinkData,exports.getSplitStyles=getSplitStyles,exports.handleCheckIsEditableLabel=handleCheckIsEditableLabel,exports.handleCheckIsShowLabel=handleCheckIsShowLabel,exports.handleGetArialLabel=handleGetArialLabel,exports.handleGetLabelToDisplay=handleGetLabelToDisplay;
