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