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