"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"),translate=require("../settings/configs/translate.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,translateSetting:t,styles:l,pageContext:a,isUseTranslatedValue:s,builderProps:r,isLiquid:o=!1,isForceValue:n})=>{let i=!s||n?e:helpers.getDynamicSourceLocales({val:e,pageContext:a,settingId:helpers.createSettingId({id:t??translate.Button?.label?.id}),uid:r?.uidTranslate??r?.uid,isCapitalize:l?.typo?.attrs?.transform==="capitalize"});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"],n=["#","mailto:","tel:"],i=e?.link??"",c="/"===i,p=e?.link!==void 0&&""!==e.link,h=new RegExp(/^https?:\/\//i),g=p&&h.test(i);p&&i.toLowerCase().startsWith("mailto:")&&i.includes("+")&&(i=helpers.normalizeMailto(i));let d=()=>{if(o.find(e=>i.includes(e)))return!0;let t=n.find(e=>i.startsWith(e));return!(!t||helpers.checkIsScrollToTop(e)||"STATIC"===r&&helpers.checkIsOpenPopup(e))},u=helpers.isLinkedToSalesPage(e?.type),I=!!a&&(g||helpers.isShopifyDomain(p,i)||d()||c||u),S=i;s&&(helpers.isShopifyDomain(p,i)||c)&&(S=e?.isTranslate?"$locationOrigin"+i:"{{ request.origin }}{{ routes.root_url | split: '/' | join: '/' }}"+i);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:n,isUseTranslatedValue:i=!0}=e,{label:c,iconSvg:p,btnLink:h,loading:g,options:d,disabled:u,iconVisible:I,shouldClearSpace:S}=r,[k,y]=getSplitStyles(t),L=getCleanedStyles(s,u),b=styles.getCustomCssStyles({styles:s,uid:o?.uid,builderAttrs:n,enableHoverEffect:r.enableHoverEffect??!0}),C=getDataState(g),D=getDataId(o?.uidInteraction,l,o?.uid),f=e=>{let{isLiquid:t}=e??{};return handleGetArialLabel({label:c,isLiquid:t})},T=e=>{let{isLiquid:t,translateSetting:l,isForceValue:s}=e??{};return handleGetLabelToDisplay({pageContext:a??{},label:c,translateSetting:l,isForceValue:s,builderProps:o,styles:L,isLiquid:t,...t&&{pageContext:a},...t&&{isUseTranslatedValue:i}})},w=e=>{let{isLiquid:t}=e??{},l=T({isLiquid:t});return handleCheckIsShowLabel(l,S)},m=e=>{let{isLiquid:t,mode:l}=e??{};return handleCheckIsEditableLabel({options:d,isLiquid:t,...!t&&l&&{mode:l}})},x=checkIsShowIcon(p,I),E=checkIsScrollToElement(h);return{customCss:b,wrapStyle:k,restStyle:y,dataState:C,dataIdAttr:D,isShowIcon:x,isScrollToElement:E,getArialLabel:f,getLabelToDisplay:T,checkIsShowLabel:w,checkIsEditableLabel:m}},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;
