"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var core=require("@gem-sdk/core"),React=require("react");const EMPTY_TAGS=["SCRIPT"],ALLOWED_EMPTY_TAG=["EMBED","IMG","INPUT","PICTURE","VIDEO"],useCSSCode=(e,t)=>{let s=core.useEditorMode(),{editorData:p}=e||{},{customLabel:a}=t||{},l=React.useCallback((e,t,s)=>`
      <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>${a||"Custom Code"}</span>
        ${e||t||s?'<span class="gp-text-[#676767] gp-text-12 gp-leading-5">Publish the page to see the content.</span>':""}
      </p>`,[a]),r=(e,t)=>{let s=document.createElement("div");s.innerHTML=e;let p=s.childNodes,a=!1,l=!0;if(p.length>0){p.forEach(e=>{EMPTY_TAGS.includes(e?.tagName)&&(a=!0,e?.remove())});let e=s.childNodes;e.forEach(e=>{if(ALLOWED_EMPTY_TAG.includes(e?.tagName))l=!1;else if(e?.nodeName!=="#comment"){let t=e?.textContent?.trim();t&&(l=!1)}})}return l&&(l=!s?.textContent?.trim()),t&&(a=!0),{empty:l,hasScript:a}},n=React.useMemo(()=>{if("edit"===s){let{empty:e,hasScript:t}=r(p?.html||"",p?.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 l(p?.css||"",p?.javascript||"",p?.html||"")}return p?.html?.trim()},[s,p?.html,p?.javascript,p?.css,l]),o=e=>{if(2===e.detail){let e=new CustomEvent("editor:toolbar:open-custom-code",{bubbles:!0});window.dispatchEvent(e)}};return{mode:s,htmlPlainText:n,handleDoubleClickCustomCode:o}};exports.default=useCSSCode;
