import{useEditorMode as e}from"@gem-sdk/core";import{useCallback as t,useMemo as p}from"react";let EMPTY_TAGS=["SCRIPT"],ALLOWED_EMPTY_TAG=["EMBED","IMG","INPUT","PICTURE","VIDEO"],useCSSCode=(s,l)=>{let n=e(),{editorData:a}=s||{},{customLabel:i}=l||{},o=t((e,t,p)=>`
      <p class="gp-text-center gp-text-sm gp-py-4 gp-leading-6 gp-text-light-500 gp-flex gp-flex-col gp-gap-[4px]">
       <span>${i||"Custom Code"}</span>
        ${e||t||p?'<span class="gp-text-[#676767] gp-text-12 gp-leading-5">Publish the page to see the content.</span>':""}
      </p>`,[i]),r=(e,t)=>{let p=document.createElement("div");p.innerHTML=e;let s=p.childNodes,l=!1,n=!0;if(s.length>0){s.forEach(e=>{EMPTY_TAGS.includes(e?.tagName)&&(l=!0,e?.remove())});let e=p.childNodes;e.forEach(e=>{if(ALLOWED_EMPTY_TAG.includes(e?.tagName))n=!1;else if(e?.nodeName!=="#comment"){let t=e?.textContent?.trim();t&&(n=!1)}})}return n&&(n=!p?.textContent?.trim()),t&&(l=!0),{empty:n,hasScript:l}},g=p(()=>{if("edit"===n){let{empty:e,hasScript:t}=r(a?.html||"",a?.javascript||"");if(t)return`
        <div class="gp-py-4 gp-font-[sans-serif] gp-flex gp-flex-col gp-gap-[4px]" >
          <p class="gp-text-center gp-text-sm  gp-leading-[21px] gp-text-[#676767] ">
            Publish the page to see the content.
          </p>
        </div>
        `;if(e)return o(a?.css||"",a?.javascript||"",a?.html||"")}return a?.html?.trim()},[n,a?.html,a?.javascript,a?.css,o]),c=e=>{if(2===e.detail){let e=new CustomEvent("editor:toolbar:open-custom-code",{bubbles:!0});window.dispatchEvent(e)}};return{mode:n,htmlPlainText:g,handleDoubleClickCustomCode:c}};export{useCSSCode as default};
