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