import{html as e,css as t,unsafeCSS as i}from"../../../../lit/index.js";import{store as o}from"./haxcms-site-store.js";import{HaxStore as a,HAXStore as s}from"../../../hax-body/lib/hax-store.js";import{autorun as n,toJS as l}from"../../../../mobx/dist/mobx.esm.js";import"../ui-components/magic/site-view.js";import{ResponsiveUtilityBehaviors as d}from"../../../responsive-utility/lib/responsive-utility-behaviors.js";import{localStorageSet as r,winEventsElement as c,mimeTypeToName as h}from"../../../utils/utils.js";import"../../../simple-icon/simple-icon.js";import"../../../simple-icon/lib/simple-icons.js";import{HAXCMSThemeParts as m}from"./utils/HAXCMSThemeParts.js";import{HAXCMSI18NMixin as p}from"./utils/HAXCMSI18NMixin.js";import"../../../rpg-character/rpg-character.js";import"../../../app-hax/lib/v1/app-hax-top-bar.js";import"../../../app-hax/lib/v1/app-hax-user-menu.js";import"../../../app-hax/lib/v1/app-hax-user-menu-button.js";import{DDD as u}from"../../../d-d-d/d-d-d.js";import{SuperDaemonInstance as b}from"../../../super-daemon/super-daemon.js";import"../../../super-daemon/lib/super-daemon-search.js";import{MicroFrontendRegistry as g}from"../../../micro-frontend-registry/micro-frontend-registry.js";import{enableServices as v}from"../../../micro-frontend-registry/lib/microServices.js";import{UserScaffoldInstance as x}from"../../../user-scaffold/user-scaffold.js";import"../../../simple-modal/simple-modal.js";import"./haxcms-site-insights.js";import"../../../simple-fields/lib/simple-fields-form.js";import"./micros/haxcms-button-add.js";import"./haxcms-darkmode-toggle.js";import"../ui-components/site/site-remote-content.js";import"../../../page-flag/page-flag.js";import"../../../../wired-elements/lib/wired-button.js";new URL("../../../app-hax/lib/assets/images/ButtonBGLM.svg",import.meta.url).href,new URL("../../../app-hax/lib/assets/images/ButtonBGDM.svg",import.meta.url).href;const f=new URL("../../../app-hax/lib/assets/images/Logout.svg",import.meta.url).href;class HAXCMSSiteEditorUI extends(m(p(c(d(u))))){static get styles(){return[super.styles,t`
        :host *:not(:defined) {
          display: none;
        }
        :host {
          display: block;
          position: relative;
          height: 48px;
          left: 0;
          top: 0;
          right: 0;
          margin-top: 0;
          opacity: 1;
          transition: all 0.6s ease-in-out;
          background-color: var(--haxcms-system-bg, #eeeeee);
          z-index: 10000;
          visibility: visible;
        }
        :host([edit-mode]) {
          z-index: 9999;
        }
        :host *[hidden] {
          display: none;
        }
        simple-tooltip:not(:defined) {
          display: none !important;
        }
        :host([painting]) {
          opacity: 0;
          margin-top: -48px;
          visibility: hidden;
        }
        #editbutton {
          visibility: hidden;
          opacity: 0;
        }

        #deletebutton {
          visibility: hidden;
          opacity: 0;
        }

        :host([page-allowed]) #editbutton,
        :host([page-allowed]) #editdetails,
        :host([page-allowed]) #deletebutton {
          visibility: visible;
          opacity: 1;
        }
        #addmenubutton:hover,
        #addmenubutton:active,
        #addmenubutton:focus,
        #addmenubutton haxcms-button-add:hover,
        #addmenubutton haxcms-button-add:active,
        #addmenubutton haxcms-button-add:focus,
        #editbutton[icon="icons:save"]:focus,
        #editbutton[icon="icons:save"]:active,
        #editbutton[icon="icons:save"]:hover {
          background-color: var(--simple-colors-default-theme-light-green-1);
        }
        #addmenubutton,
        #addmenubutton haxcms-button-add,
        #editbutton[icon="icons:save"] {
          --simple-toolbar-border-color: var(
            --simple-colors-default-theme-light-green-2
          );
          color: var(--simple-colors-default-theme-green-11);
          background-color: var(--simple-colors-default-theme-grey-1);
        }

        haxcms-button-add {
          background-color: var(--simple-colors-default-theme-grey-1);
        }

        simple-toolbar-menu-item a {
          color: var(--simple-colors-default-theme-grey-12);
          text-decoration: none;
        }

        #deletebutton,
        #cancelbutton {
          color: var(--simple-colors-default-theme-red-11);
          --simple-toolbar-border-color: var(
            --simple-colors-default-theme-red-2
          );
        }
        .merlin {
          color: var(--simple-colors-default-theme-purple-10);
          --simple-toolbar-border-color: var(
            --simple-colors-default-theme-purple-2
          );
        }
        simple-toolbar-button.merlin:hover,
        simple-toolbar-button.merlin:active,
        simple-toolbar-button.merlin:focus {
          background-color: var(--simple-colors-default-theme-purple-1);
        }
        #deletebutton:hover,
        #deletebutton:active,
        #deletebutton:focus,
        #cancelbutton:hover,
        #cancelbutton:active,
        #cancelbutton:focus {
          background-color: var(--simple-colors-default-theme-red-1);
        }
        simple-toolbar-menu:hover,
        simple-toolbar-menu:active,
        simple-toolbar-menu:focus,
        simple-toolbar-button:hover,
        simple-toolbar-button:active,
        simple-toolbar-button:focus,
        haxcms-button-add:hover,
        haxcms-button-add:active,
        haxcms-button-add:focus {
          background-color: var(--hax-ui-background-color-accent);
          color: var(--hax-ui-color);
        }
        simple-toolbar-button:hover,
        simple-toolbar-button:active,
        simple-toolbar-button:focus,
        haxcms-button-add:hover,
        haxcms-button-add:active,
        haxcms-button-add:focus {
          --simple-toolbar-border-color: var(--hax-ui-color-accent);
        }
        :host(:hover),
        :host(:active),
        :host(:focus) {
          opacity: 1;
        }
        simple-tooltip {
          --simple-tooltip-background: #000000;
          --simple-tooltip-opacity: 1;
          --simple-tooltip-text-color: #ffffff;
          --simple-tooltip-delay-in: 0;
          --simple-tooltip-duration-in: 200ms;
          --simple-tooltip-duration-out: 0;
          --simple-tooltip-border-radius: 0;
          --simple-tooltip-font-size: 14px;
          font-family: "Press Start 2P", sans-serif;
        }
        app-hax-top-bar {
          z-index: 1000;
          right: 0;
          left: 0;
          position: fixed;
        }
        :host([dark-mode]) app-hax-top-bar {
          --bg-color: #222;
          --accent-color: #fff;
        }
        app-hax-top-bar::part(top-bar) {
          grid-template-columns: 5% 85% 10%;
          overflow: visible;
        }
        .haxLogo {
          color: var(--simple-colors-default-theme-accent-11, black);
        }
        :host([dark-mode]) .haxLogo:hover,
        :host([dark-mode]) .haxLogo:focus,
        :host([dark-mode]) .haxLogo:active,
        .haxLogo:hover,
        .haxLogo:focus,
        .haxLogo:active {
          color: var(--haxcms-color);
        }
        .haxLogo simple-icon-lite {
          --simple-icon-height: 40px;
          --simple-icon-width: 40px;
          margin: 4px;
        }
        .soundToggle {
          position: relative;
          display: inline-flex;
          vertical-align: top;
        }

        .soundToggle img {
          width: 24px;
          height: 24px;
        }

        :host([edit-mode]) simple-toolbar simple-toolbar-button,
        :host([edit-mode]) simple-toolbar simple-toolbar-menu {
          --simple-toolbar-border-color: var(--hax-ui-color-accent);
          --simple-toolbar-border-color: #dddddddd;
        }

        simple-toolbar simple-toolbar-button,
        simple-toolbar simple-toolbar-menu {
          --simple-toolbar-border-radius: 0;
          background-color: var(--simple-colors-default-theme-grey-1);
        }

        app-hax-search-bar {
          vertical-align: middle;
          display: inline-flex;
        }
        simple-toolbar {
          align-items: stretch;
          justify-content: center;
          height: var(--top-bar-height);
          --simple-toolbar-button-disabled-border-color: transparent;
          --simple-toolbar-button-disabled-opacity: 0.3;
          --simple-toolbar-button-padding: 3px 6px;
        }
        simple-toolbar[dark-mode] {
          --simple-toolbar-button-color: #e0e0e0;
          --simple-toolbar-button-hover-color: #fff;
          --simple-toolbar-button-bg: #222;
          --simple-toolbar-button-hover-bg: #000;
        }
        simple-toolbar::part(buttons) {
          flex: 0 1 auto;
        }
        .ops-panel {
          justify-content: space-around;
          display: flex;
          padding: 4px 0px;
        }

        .topbar-character {
          cursor: pointer;
          display: inline-block;
          border: none;
          border-radius: 0px;
          padding: 0 8px;
          margin: 0 0 0 16px;
          background-color: transparent;
          height: 48px;
          max-width: 160px;
          overflow: hidden;
          word-break: break-all;
          transition: all 0.6 ease-in-out;
          color: #222;
        }
        .characterbtn-name {
          font-family: "Press Start 2P", sans-serif;
          margin-left: 8px;
          font-size: 12px;
          vertical-align: bottom;
          line-height: 48px;
          overflow: hidden;
          text-overflow: ellipsis;
          height: 48px;
          word-break: break-all;
        }
        :host([dark-mode]) .topbar-character,
        :host([dark-mode]) .topbar-character {
          color: #e0e0e0;
          background-color: #222;
        }
        .topbar-character rpg-character {
          margin: -4px -14px 0px -10px;
          height: 52px;
          width: 64px;
          display: inline-block;
          transform: scale(0.7);
          transition: all 0.5 ease-in-out;
        }
        .topbar-character:hover rpg-character,
        .topbar-character:focus rpg-character {
          transform: scale(0.9);
        }

        .mysiteslink {
          text-decoration: none;
        }

        .logout::part(menu-button) {
          background-image: url("${i(f)}");
          background-repeat: no-repeat;
          background-position: center center;
          text-align: center;
          background-size: cover;
          border-top: 0px;
          border-bottom: 0px;
          padding: 10px;
          font-family: "Press Start 2P", sans-serif;
        }
        app-hax-user-menu app-hax-user-menu-button::part(menu-button) {
          font-family: "Press Start 2P", sans-serif;
          font-size: 12px;
        }
        simple-toolbar-menu,
        simple-toolbar-button {
          min-width: 48px;
          margin: 0;
          --simple-toolbar-border-color: #dddddddd;
        }
        :host([responsive-size="xs"]) #deletebutton,
        :host([responsive-size="sm"]) #deletebutton,
        :host([responsive-size="md"]) #deletebutton,
        :host([responsive-size="xs"]) #cancelbutton,
        :host([responsive-size="sm"]) #cancelbutton,
        :host([responsive-size="md"]) #cancelbutton {
          margin-right: 16px;
        }

        @media screen and (max-width: 800px) {
          :host([edit-mode]) {
            bottom: unset;
          }
          app-hax-top-bar::part(top-bar) {
            display: grid;
          }
          #undo,
          #redo {
            display: none;
          }
          .topbar-character {
            padding: 0;
            margin: 0;
          }
          .characterbtn-name {
            padding: 0;
            margin: 0;
            width: 30px;
            display: inline-flex;
            overflow: hidden;
            text-overflow: ellipsis;
            letter-spacing: -2px;
            margin-left: -6px;
          }
          simple-toolbar {
            --simple-toolbar-button-padding: 3px 3px;
          }
          .characterbtn-name,
          haxcms-button-add,
          simple-toolbar-menu,
          simple-toolbar-button {
            font-size: 10px;
          }
          simple-toolbar-menu {
            --icon-offset-right: 2px;
            --icon-offset-left: 2px;
          }
          simple-toolbar-menu::part(dropdown-icon) {
            right: 0;
            top: 10px;
          }
          :host([edit-mode]) #deletebutton,
          :host([edit-mode]) #addmenubutton,
          :host([edit-mode]) #editdetails {
            display: none;
          }
        }
        @media (max-width: 600px) {
          .haxLogo {
            display: none;
          }

          .topbar-character rpg-character {
            margin: 0 0 0px -8px;
            height: 10px;
            width: 48px;
          }
          simple-toolbar {
            --simple-toolbar-button-padding: 0px;
            justify-content: space-between;
            background-color: white;
            height: auto;
          }
          .characterbtn-name {
            padding: 0px;
            margin: -42px 8px 0px 0px;
            width: 40px;
            display: block;
            text-overflow: ellipsis;
            font-size: 12px;
            font-family: auto;
            letter-spacing: normal;
            font-weight: normal;
          }
        }
      `]}static get tag(){return"haxcms-site-editor-ui"}_expandSettingsPanel(e){this.shadowRoot.querySelector("#content-edit").click()}selectFileToProcess(){import("../../../file-system-broker/file-system-broker.js").then((async e=>{const t=globalThis.FileSystemBroker.requestAvailability(),i=await t.getFileContents("*"),o=t.fileHandler;let a=o.name.split("."),s="";a.length>1&&(s=a.pop()),b.waveWand(["","/",{operation:"file-selected",contents:i,data:o,type:s},"hax-agent","Agent"],this.shadowRoot.querySelector("#merlin"),"coin2")}))}setProcessingVisual(){let e=globalThis.document.createElement("simple-icon-lite");e.icon="hax:loading",e.style.setProperty("--simple-icon-height","40px"),e.style.setProperty("--simple-icon-width","40px"),e.style.height="150px",e.style.marginLeft="8px",o.toast("Processing",5e3,{hat:"construction",speed:100,walking:!0,slot:e})}async processFileContentsBasedOnUserDesire(e,t,i){l(x.data).event;switch(this.setProcessingVisual(),t){case"upload":case"link":case"insert-file":"upload"===t?this.dispatchEvent(new CustomEvent("hax-file-upload",{bubbles:!0,cancelable:!0,composed:!0,detail:{file:e.data,placeHolderElement:null,operationType:i}})):"link"===t?(!1===o.editMode&&(o.editMode=!0),setTimeout((()=>{let t=s.activeHaxBody.haxInsert("p","",{});this.dispatchEvent(new CustomEvent("hax-file-upload",{bubbles:!0,cancelable:!0,composed:!0,detail:{file:e.data,placeHolderElement:t,operationType:i}}))}),300)):(!1===o.editMode&&(o.editMode=!0),setTimeout((()=>{let t=s.activeHaxBody.haxInsert("p","",{});this.dispatchEvent(new CustomEvent("hax-file-upload",{bubbles:!0,cancelable:!0,composed:!0,detail:{file:e.data,placeHolderElement:t,operationType:i}}))}),300));break;case"insert-html":case"create-sibling":case"create-child":case"create-branch":let a=null,n=new FormData;switch(e.type){case"docx":case"doc":if(n.append("upload",e.data),a="@core/docxToHtml","create-branch"===t){a="@haxcms/docxToSite",n.append("method","branch"),n.append("type","branch");const e=l(o.activeItem);n.append("parentId",e.parent)}break;case"md":case"txt":a="@core/mdToHtml",n={md:e.contents}}let d={};if(a){if("insert-html"===t)d=await g.call(a,n),200==d.status&&this.insertElementsFromContentBlob(d.data.contents||d.data);else if(d=await g.call(a,n),200==d.status)if(["create-sibling","create-child"].includes(t))this.createNewNode(t.replace("create-",""),e.data.name,d.data.contents||d.data);else if(d.data&&""!=d.data.contents){let e={};e.items=d.data.items,await import("../../../outline-designer/outline-designer.js").then((async t=>{e.jwt=l(o.jwt),e.site={name:l(o.manifest.metadata.site.name)};const i=globalThis.document.createElement("outline-designer");i.items=d.data.items,i.eventData=e,i.storeTools=!0;const a=globalThis.document.createElement("button");a.innerText="Confirm",a.classList.add("hax-modal-btn"),a.addEventListener("click",(async e=>{const t=await i.getData();let a=0,s=0,n=0;t.items.map((e=>{e.delete?a++:e.new?n++:e.modified&&s++}));let l=`${n>0?`‣ ${n} new pages will be created\n`:""}${s>0?`‣ ${s} pages will be updated\n`:""}${a>0?`‣ ${a} pages will be deleted\n`:""}`,d=!1;if(d=""==l||globalThis.confirm(`Saving will commit the following actions:\n${l}\nAre you sure?`),d){o.cmsSiteEditorAvailability().querySelector("#createajax").body=t,this.setProcessingVisual(),o.cmsSiteEditorAvailability().querySelector("#createajax").generateRequest();const e=new CustomEvent("simple-modal-hide",{bubbles:!0,composed:!0,cancelable:!0,detail:{}});globalThis.dispatchEvent(e)}}));const s=globalThis.document.createElement("button");s.innerText="Cancel",s.classList.add("hax-modal-btn"),s.classList.add("cancel"),s.addEventListener("click",(e=>{const t=new CustomEvent("simple-modal-hide",{bubbles:!0,composed:!0,cancelable:!0,detail:{}});globalThis.dispatchEvent(t)}));const n=globalThis.document.createElement("div");n.appendChild(a),n.appendChild(s),this.dispatchEvent(new CustomEvent("simple-modal-show",{bubbles:!0,cancelable:!0,composed:!0,detail:{title:"Confirm structure",elements:{content:i,buttons:n},modal:!0,styles:{"--simple-modal-titlebar-background":"transparent","--simple-modal-titlebar-color":"black","--simple-modal-width":"90vw","--simple-modal-min-width":"300px","--simple-modal-z-index":"100000000","--simple-modal-height":"90vh","--simple-modal-min-height":"400px","--simple-modal-titlebar-height":"64px","--simple-modal-titlebar-color":"black","--simple-modal-titlebar-height":"80px","--simple-modal-titlebar-background":"orange"}}}))}))}}else"insert-html"===t?this.insertElementsFromContentBlob(e.contents):"create-branch"!==t&&this.createNewNode(t.replace("create-",""),e.data.name,e.contents)}}async createNewNode(e,t="New page",i="<p></p>"){let a=null,s=null;const n=l(o.activeItem);if(n)if("sibling"===e)s=n.parent,a=parseInt(n.order);else if("child"===e){s=n.id;let e=l(await o.getLastChildItem(n.id)).order;a=0,(e||0===e)&&(a=e+1)}else s=null,a=0;""==t&&(t="New page");var d={node:{title:t,location:"",contents:i},order:a,parent:s};this.dispatchEvent(new CustomEvent("haxcms-create-node",{bubbles:!0,composed:!0,cancelable:!0,detail:{originalTarget:this,values:d}}))}insertElementsFromContentBlob(e){let t=!1;!1===o.editMode?(o.editMode=!0,t=!0):this.activeNode.hasAttribute("slot")&&(a=this.activeNode.getAttribute("slot"));const i=globalThis.document.createElement("div");i.innerHTML=e;let a=!1;if(!t&&this.activeNode&&this.activeNode.parentNode)for(var n=i.children.length-1;n>0;n--)a&&i.children[n].setAttribute("slot",a),this.activeNode.parentNode.insertBefore(i.children[n],this.activeNode.nextSibling);else setTimeout((()=>{for(var e=i.children.length-1;e>0;e--)s.activeHaxBody.appendChild(i.children[e]);setTimeout((()=>{s.activeHaxBody.scrollHere(this.activeNode),setTimeout((()=>{s.activeHaxBody.scrollHere(this.activeNode)}),500)}),1e3)}),300);s.toast(this.t.contentImported)}async insertUrl(e,t){if(!1===o.editMode&&(o.editMode=!0),t){const t=await g.call("@core/metadata",{q:e});if(t.data&&(t.data["og:title"]||t.data.title)){let i={title:t.data["og:title"]||t.data.title,source:e};s.insertLogicFromValues(i,this)}}}constructor(){super(),this.__winEvents={"can-redo-changed":"_redoChanged","can-undo-changed":"_undoChanged","hax-drop-focus-event":"_expandSettingsPanel","jwt-logged-in":"_jwtLoggedIn","super-daemon-close":"sdCloseEvent"},this.rpgHat="none",this.darkMode=!1,this.__editText="Edit",this.userMenuOpen=!1,this.soundIcon="",this.__disposer=this.__disposer||[],this.t=this.t||{},b.allowedCallback=()=>!0,b.keyHandlerCallback=()=>{const e=this.shadowRoot.querySelector("#merlin");return o.playSound("click"),"super-daemon-modal"==e.getAttribute("data-event")?s.haxTray.collapsed=!1:(b.mini=!0,b.wand=!0,b.activeNode=this.shadowRoot.querySelector("#merlin")),b.runProgram("","*"),!0},b.noResultsSlot=()=>e`<div class="no-results">
          Expecting to see an option Merlin didn't provide?
        </div>
        <a
          @click="${e=>{s._haxStoreContribute("merlin","POP,enhancement",b.commandContext+" "+b.value)}}"
          >Make a suggestion to improve results</a
        >`,b.appendContext("CMS"),b.defineOption({title:"Magic File Wand",icon:"hax:hax2022",priority:-1e4,tags:["Agent","help","merlin"],eventName:"super-daemon-run-program",path:"HAX/agent",value:{name:"Agent",machineName:"hax-agent",program:async(e,t)=>{const i=l(x.action),o=l(x.memory),a=l(x.data);let s=[];if("file-selected"===t.operation){switch(t.type){case"md":case"docx":case"doc":case"txt":case"html":case"htm":o.editMode||(s.push({title:`New Sibling Page from ${t.type}`,icon:"hax:add-page",tags:["agent"],value:{target:this,method:"processFileContentsBasedOnUserDesire",args:[t,"create-sibling"]},eventName:"super-daemon-element-method",path:"Page created next to current"}),s.push({title:`New Child Page from ${t.type}`,icon:"hax:add-child-page",tags:["agent"],value:{target:this,method:"processFileContentsBasedOnUserDesire",args:[t,"create-child"]},eventName:"super-daemon-element-method",path:"Page created under current"}),["docx","doc"].includes(t.type)&&s.push({title:`Create outline from ${t.type}`,icon:"hax:site-map",tags:["agent"],value:{target:this,method:"processFileContentsBasedOnUserDesire",args:[t,"create-branch"]},eventName:"super-daemon-element-method",path:"H1,H2 tags create menu pages"})),s.push({title:`Insert ${t.type} contents in Page`,icon:"hax:html-code",tags:["agent"],value:{target:this,method:"processFileContentsBasedOnUserDesire",args:[t,"insert-html"]},eventName:"super-daemon-element-method",path:"Content converted to HTML and inserted"});break;case"png":case"jpeg":case"gif":case"jpg":s.push({title:`Insert ${t.type} in page`,icon:"editor:insert-photo",tags:["agent"],value:{target:this,method:"processFileContentsBasedOnUserDesire",args:[t,"insert-file","image"]},eventName:"super-daemon-element-method",path:"Image embedded in page"});break;case"mp4":s.push({title:`Insert ${t.type} in page`,icon:"av:play-circle-filled",tags:["agent"],value:{target:this,method:"processFileContentsBasedOnUserDesire",args:[t,"insert-file","video"]},eventName:"super-daemon-element-method",path:"Video embedded in page"});break;case"midi":case"mid":case"mp3":s.push({title:`Insert ${t.type} in page`,icon:"av:volume-up",tags:["agent"],value:{target:this,method:"processFileContentsBasedOnUserDesire",args:[t,"insert-file","audio"]},eventName:"super-daemon-element-method",path:"Audio embedded in page"});break;case"pdf":s.push({title:`Embed ${t.type} in page`,icon:"hax:file-pdf",tags:["agent"],value:{target:this,method:"processFileContentsBasedOnUserDesire",args:[t,"insert-file","pdf"]},eventName:"super-daemon-element-method",path:"PDF embedded in a frame element"})}s.push({title:`Link to ${t.type} file`,icon:"editor:insert-link",tags:["agent"],value:{target:this,method:"processFileContentsBasedOnUserDesire",args:[t,"link","link"]},eventName:"super-daemon-element-method",path:"File uploaded and linked to"}),s.push({title:`Just Upload ${t.type} file`,icon:"file-upload",tags:["agent"],value:{target:this,method:"processFileContentsBasedOnUserDesire",args:[t,"upload","upload-only"]},eventName:"super-daemon-element-method",path:"File uploaded for later use"})}else if("drop"===i.type&&"drop"===t.type){const e=a.file,t=await e.text();let i=e.name.split("."),o="";i.length>1&&(o=i.pop()),b.waveWand(["","/",{operation:"file-selected",contents:t,data:e,type:o},"hax-agent","Agent"],this.shadowRoot.querySelector("#merlin"),"coin2")}else s=[{title:"Select file..",icon:"folder-open",tags:["agent"],value:{target:this,method:"selectFileToProcess",args:[]},eventName:"super-daemon-element-method",path:"Watch Merlin work his magic!"}],this.selectFileToProcess();return s}}}),s.ready&&(["site-remote-content","citation-element","page-flag","site-view","site-collection-list","collection-list","collection-item"].map((e=>{let t=globalThis.document.createElement(e);s.haxAutoloader.appendChild(t)})),s.primativeHooks.a||(s.primativeHooks.a={}),s.primativeHooks.a.setupActiveElementForm=e=>{const t=o.getManifestItems(!0);var i=[{text:`-- ${this.t.selectPage} --`,value:null}];t.forEach((e=>{if(e.id!=this.itemId){let o=e,a="- ";for(;o&&null!=o.parent;)o=t.find((e=>e.id==o.parent)),o&&(a="--"+a);i.push({text:a+e.title,value:e.id})}}))}),this.t={...this.t,selectPage:"Select page",backToSiteList:"Back to site list",mySites:"My sites",cancel:"Cancel",unsavedChangesWillBeLostIfSelectingOkAreYouSure:"Unsaved changes will be lost if selecting OK, are you sure?",editDetails:"Page details",add:"Add",editSettings:"Edit settings",source:"Source",viewSource:"View source",confirmHtmlSourceExit:"HTML Source changes will not be saved without pressing the `Update HTML` button, Save without HTML code editor changes?",findMedia:"Find media",undo:"Undo",redo:"Redo",media:"Media",outline:"Outline",blocks:"Blocks",addBlock:"Add block",addPage:"Add page",addChildPage:"Add child page",clonePage:"Clone page",delete:"Delete page",shareSite:"Share site",siteSettings:"Site settings",themeSettings:"Theme settings",seoSettings:"SEO settings",authorSettings:"Author settings",close:"Close",settings:"Settings",edit:"Edit",configureBlock:"Configure block",configure:"Configure",save:"Save",newJourney:"New Journey",accountInfo:"Account Info",outlineDesigner:"Outline designer",pageOutline:"Page outline",more:"More",siteActions:"Site actions",insights:"Insights dashboard (beta)",viewBuilder:"View builder (alpha)",merlin:"Merlin",summonMerlin:"Summon Merlin",logOut:"Log out",menu:"Menu",showMore:"More",contentImported:"Content imported!"},this.backText="Site list",this.painting=!0,this.pageAllowed=!1,this.editMode=!1,this.__editIcon="hax:page-edit",this.icon="hax:site-settings",this.manifestEditMode=!1,this.backLink="../../",this.activeTagName="",this.activeNode=null,this.activeDrag=!1,this.activeType=null,globalThis.appSettings&&globalThis.appSettings.backLink&&(this.backLink=globalThis.appSettings.backLink),n((()=>{const e=l(x.action),t=l(x.data);x.active&&x.memory.isLoggedIn&&null===b.programName&&"drag"===e.type?(this.activeDrag=!0,this.activeType=t.value||t.architype):x.active&&x.memory.isLoggedIn&&null===b.programName&&"dragleave"===e.type&&(this.activeDrag=!1,this.activeType=null)})),n((()=>{const e=l(s.activeGizmo);e&&e.title&&(this.activeTagName=e.title)})),n((()=>{this.activeNode=l(s.activeNode)})),n((()=>{const e=l(o.badDevice);if(!1===e){const e=globalThis.document.createElement("link");e.setAttribute("href","https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap"),e.setAttribute("rel","stylesheet"),e.setAttribute("fetchpriority","low"),globalThis.document.head.appendChild(e)}else!0===e&&globalThis.document.body.classList.add("bad-device")})),n((()=>{this.darkMode=l(o.darkMode),this.dark=this.darkMode,l(o.darkMode)?(b.dark=!0,b.toastInstance.darkMode=!0,s.globalPreferences.haxUiTheme="haxdark"):(s.globalPreferences.haxUiTheme="hax",b.dark=!1,b.toastInstance.darkMode=!1)})),n((()=>{this.soundIcon=l(o.soundStatus)?new URL("../../../app-hax/lib/assets/images/FullVolume.svg",import.meta.url).href:new URL("../../../app-hax/lib/assets/images/Silence.svg",import.meta.url).href})),setTimeout((()=>{import("./haxcms-outline-editor-dialog.js"),import("./haxcms-share-dialog.js")}),0)}soundToggle(){const e=!l(o.soundStatus);o.soundStatus=e,r("app-hax-soundStatus",e),e?(o.toast("Can you hear me now? Good.",2e3,{hat:"random"}),o.playSound("click")):o.toast("Sound off.. hey.. HELLO!?!",2e3,{fire:!0})}closeMenu(){this.userMenuOpen=!1}toggleMenu(){this.userMenuOpen=!this.userMenuOpen,o.playSound("click")}getIconPosition(e){return["xl","lg"].includes(e)?"left":"top"}render(){return e`
      <app-hax-top-bar part="top-bar" ?edit-mode="${this.editMode}">
        <span slot="left" class="home-btn">
          <a
            href="${this.backLink}"
            class="haxLogo"
            id="backtosites"
            part="hax-logo"
          >
            <simple-icon-lite icon="hax:hax2022"></simple-icon-lite>
          </a>
          <simple-tooltip for="backtosites" position="right"
            >${this.backText}</simple-tooltip
          >
          <slot name="haxcms-site-editor-ui-prefix-avatar"></slot>
        </span>
        <simple-toolbar
          slot="center"
          ?dark="${!this.darkMode}"
          icon-position="${this.getIconPosition(this.responsiveSize)}"
          show-text-label
          label="${this.t.showMore}"
        >
          <slot name="haxcms-site-editor-ui-prefix-buttons"></slot>
          <simple-toolbar-button
            hidden
            id="editbutton"
            icon="${this.__editIcon}"
            icon-position="${this.getIconPosition(this.responsiveSize)}"
            @click="${this._editButtonTap}"
            label="${this.__editText}"
            show-text-label
            data-primary="4"
            voice-command="edit (this) page"
          ></simple-toolbar-button>
           <simple-toolbar-button
            icon="icons:undo"
            icon-position="${this.getIconPosition(this.responsiveSize)}"
            ?disabled="${!this.canUndo}"
            @click="${this.haxButtonOp}"
            label="${this.t.undo}"
            data-event="undo"
            id="undo"
            ?hidden="${!this.editMode}"
            voice-command="undo"
            show-text-label
          >
          </simple-toolbar-button>
          <simple-toolbar-button
            icon="icons:redo"
            @click="${this.haxButtonOp}"
            ?disabled="${!this.canRedo}"
            ?hidden="${!this.editMode}"
            label="${this.t.redo}"
            data-event="redo"
            id="redo"
            voice-command="redo"
            icon-position="${this.getIconPosition(this.responsiveSize)}"
            show-text-label
          >
          </simple-toolbar-button>

          <simple-toolbar-button
            id="cancelbutton"
            icon="icons:cancel"
            icon-position="${this.getIconPosition(this.responsiveSize)}"
            @click="${this._cancelButtonTap}"
            ?hidden="${!this.editMode}"
            ?disabled="${!this.editMode}"
            show-text-label
            tabindex="${this.editMode?"0":"-1"}"
            label="${this.t.cancel}"
            voice-command="cancel (editing)"
          ></simple-toolbar-button>

          <simple-toolbar-menu
            id="addmenubutton"
            ?hidden="${this.editMode}"
            ?disabled="${this.editMode}"
            icon="hax:add-page"
            icon-position="${this.getIconPosition(this.responsiveSize)}"
            label="${this.t.add}.."
            tabindex="${this.editMode?"-1":"0"}"
            @dblclick="${this._addPageClick}"
            show-text-label
          >
            <simple-toolbar-menu-item>
              <haxcms-button-add
                role="menuitem"
                hidden
                ?disabled="${this.editMode}"
                id="addbutton"
                show-text-label
                data-super-daemon-label="${this.t.addPage}"
                data-super-daemon-icon="hax:add-page"
                data-super-daemon-path="CMS/action/create/page"
              >
              </haxcms-button-add>
            </simple-toolbar-menu-item>
            <simple-toolbar-menu-item>
              <haxcms-button-add
                role="menuitem"
                hidden
                ?disabled="${this.editMode}"
                id="addbuttonchild"
                type="child"
                show-text-label
                data-super-daemon-path="CMS/action/create/child"
                data-super-daemon-label="${this.t.addChildPage}"
                data-super-daemon-icon="hax:add-child-page"
              ></haxcms-button-add>
            </simple-toolbar-menu-item>
              <haxcms-button-add
                role="menuitem"
                hidden
                ?disabled="${this.editMode}"
                type="duplicate"
                id="duplicatebutton"
                show-text-label
                data-super-daemon-path="CMS/action/create/duplicate"
                data-super-daemon-label="${this.t.clonePage}"
                data-super-daemon-icon="hax:duplicate"
              ></haxcms-button-add>
            </simple-toolbar-menu-item>
          </simple-toolbar-menu>
          
          <simple-toolbar-button
            ?hidden="${this.editMode}"
            ?disabled="${this.editMode}"
            tabindex="${this.editMode?"-1":"0"}"
            id="deletebutton"
            icon-position="${this.getIconPosition(this.responsiveSize)}"
            icon="icons:delete"
            @click="${this._deleteButtonTap}"
            label="${this.t.delete}"
            show-text-label
            voice-command="delete page"
          ></simple-toolbar-button>

          <simple-toolbar-button
            data-event="content-edit"
            icon="settings"
            @click="${this.haxButtonOp}"
            id="content-edit"
            label="${this.t.configureBlock}"
            ?hidden="${!this.editMode}"
            ?disabled="${!this.activeTagName||""==this.activeTagName||!this.activeNode||!this.activeNode.tagName}"
            voice-command="(modify)(configure)(edit) selected"
            controls="tray-detail"
            tooltip="${this.t.configure} ${this.activeTagName}"
            toggles
            ?toggled="${"content-edit"===this.trayDetail}"
            icon-position="${this.getIconPosition(this.responsiveSize)}"
            show-text-label
          >
          </simple-toolbar-button>
          <simple-toolbar-button
            ?hidden="${!this.editMode}"
            ?disabled="${!this.editMode}"
            data-event="content-add"
            icon="hax:add-brick"
            id="content-add"
            label="${this.t.addBlock}"
            voice-command="select blocks (menu)"
            toggles
            ?toggled="${"content-add"===this.trayDetail}"
            icon-position="${this.getIconPosition(this.responsiveSize)}"
            show-text-label
            @click="${this.haxButtonOp}"
          >
          </simple-toolbar-button>
          <simple-toolbar-button
            ?hidden="${!this.editMode}"
            ?disabled="${!this.editMode}"
            icon="hax:multimedia"
            label="${this.t.findMedia}"
            voice-command="select media (menu)"
            icon-position="${this.getIconPosition(this.responsiveSize)}"
            show-text-label
            data-event="media-program"
            @click="${this.haxButtonOp}"
          >
          </simple-toolbar-button>
          <simple-toolbar-button
           ?hidden="${!this.editMode}"
           ?disabled="${!this.editMode}"
            data-event="content-map"
            icon="hax:newspaper"
            id="content-map"
            label="${this.t.pageOutline}"
            voice-command="select content outline (menu)"
            toggles
            @click="${this.haxButtonOp}"
            ?toggled="${"content-map"===this.trayDetail}"
            icon-position="${this.getIconPosition(this.responsiveSize)}"
            show-text-label
          >
          </simple-toolbar-button>

          <simple-toolbar-button
            id="exportbtn"
            icon="hax:html-code"
            label="${this.t.viewSource}"
            data-event="view-source"
            @click="${this.haxButtonOp}"
            voice-command="view (page) source"
            icon-position="${this.getIconPosition(this.responsiveSize)}"
            show-text-label
            ?hidden="${!this.editMode}"
            ?disabled="${!this.editMode}"
          >
          </simple-toolbar-button>

          <simple-toolbar-menu
            show-text-label
            ?hidden="${this.editMode}"
            ?disabled="${this.editMode}"
            icon="hax:home-edit"
            part="morebtn"
            icon-position="${this.getIconPosition(this.responsiveSize)}"
            label="${this.t.siteActions}"
            tabindex="${this.editMode?"-1":"0"}"
          >
            <simple-toolbar-menu-item>
              <simple-toolbar-button
              ?hidden="${this.editMode}"
              ?disabled="${this.editMode}"
              tabindex="${this.editMode?"-1":"0"}"
              id="outlinebutton"
              @click="${this._outlineButtonTap}"
              icon-position="left"
              icon="hax:site-map"
              part="outlinebtn"
              show-text-label
              label="${this.t.outlineDesigner}"
            ></simple-toolbar-button>
            </simple-toolbar-menu-item>
            <simple-toolbar-menu-item>
            <simple-toolbar-button
              ?hidden="${this.editMode}"
              ?disabled="${this.editMode}"
              tabindex="${this.editMode?"-1":"0"}"
              id="sharebutton"
              @click="${this._shareButtonTap}"
              icon="social:share"
              part="sharebtn"
              show-text-label
              icon-position="left"
              label="${this.t.shareSite}"
            ></simple-toolbar-button>
            </simple-toolbar-menu-item>
            <simple-toolbar-menu-item>
            <simple-toolbar-button
              ?hidden="${this.editMode}"
              ?disabled="${this.editMode}"
              tabindex="${this.editMode?"-1":"0"}"
              id="insightsbutton"
              icon="hax:clipboard-pulse"
              part="insightsbtn"
              icon-position="left"
              @click="${this._insightsButtonTap}"
              label="${this.t.insights}"
              show-text-label
              voice-command="insights"
            ></simple-toolbar-button>
            </simple-toolbar-menu-item>
            <simple-toolbar-menu-item>
              <a href="views">
                <simple-toolbar-button
                  ?hidden="${this.editMode}"
                  ?disabled="${this.editMode}"
                  tabindex="${this.editMode?"-1":"0"}"
                  icon="hax:module"
                  icon-position="left"
                  label="${this.t.viewBuilder}"
                  show-text-label
                  voice-command="views"
                ></simple-toolbar-button>
              </a>
            </simple-toolbar-menu-item>

            <simple-toolbar-menu-item>
              <simple-toolbar-button
                @click="${this._manifestButtonTap}"
                icon-position="left"
                icon="${this.icon}"
                part="manifestbtn"
                id="manifestbtn"
                show-text-label
                ?disabled="${this.editMode}"
                ?hidden="${this.editMode}"
                tabindex="${this.editMode?"0":"-1"}"
                label="${this.t.editSettings}"
              ></simple-toolbar-button>
            </simple-toolbar-menu-item>
          </simple-toolbar-menu>
          <slot name="haxcms-site-editor-ui-suffix-buttons"></slot>
          <simple-toolbar-button
            icon="hax:wizard-hat"
            label="${this.t.merlin}"
            voice-command="${this.t.merlin}"
            icon-position="${this.getIconPosition(this.responsiveSize)}"
            class="merlin"
            id="merlin"
            @click="${this.haxButtonOp}"
            data-event="${"xs"===this.responsiveSize?"super-daemon-modal":"super-daemon"}"
            show-text-label
          ></simple-toolbar-button>
          <super-daemon-search
            @click="${this.haxButtonOp}"
            @value-changed="${this.haxButtonOp}"
            @drop="${this.dropEvent}"
            @dragenter="${this.dragenterEvent}"
            @dragleave="${this.dragleaveEvent}"
            @dragover="${this.dragoverEvent}"
            icon="hax:wizard-hat"
            id="search"
            voice-search
            class="merlin"
            data-event="${"xs"===this.responsiveSize?"super-daemon-modal":"super-daemon"}"
            ?hidden="${["xs"].includes(this.responsiveSize)}"
            mini
            wand
            droppable-type="${this.activeType}"
            ?droppable="${this.activeDrag}"
          >
          </super-daemon-search>
        </simple-toolbar>

        <app-hax-user-menu slot="right" id="user-menu" part="app-hax-user-menu"
        ?is-open="${this.userMenuOpen}">
          <button
            class="topbar-character"
            slot="menuButton"
            @click="${this.toggleMenu}"
          >
            <rpg-character
              seed="${this.userName}"
              width="68"
              height="68"
              part="rpgcharacter"
              aria-label="${this.t.menu}"
              hat="${this.rpgHat}"
            ></rpg-character>
            <span class="characterbtn-name">${this.userName}</span>
            <slot name="haxcms-site-editor-ui-topbar-character-button"></slot>
          </button>
          <div slot="pre-menu" class="ops-panel">
            <slot name="haxcms-site-editor-ui-pre-menu"></slot>
            <wired-button
              elevation="1"
              class="soundToggle"
              @click="${this.soundToggle}"
            >
              <simple-icon-lite
                src="${this.soundIcon}"
                loading="lazy"
                decoding="async"
              ></simple-icon-lite>
            </wired-button>
            <haxcms-darkmode-toggle></haxcms-darkmode-toggle>
          </div>
          <!-- <app-hax-user-menu-button
          slot="main-menu"
          icon="face"
          label="${this.t.accountInfo}"
        ></app-hax-user-menu-button> -->
          <slot slot="main-menu" name="haxcms-site-editor-ui-main-menu"></slot>
          <a class="mysiteslink" href="${this.backLink}" slot="main-menu" part="mysiteslink" tabindex="-1">
            <app-hax-user-menu-button
              icon="hax:hax2022"
              label="${this.t.mySites}"
              part="mysitesbtn"
            ></app-hax-user-menu-button>
          </a>
          <app-hax-user-menu-button
            slot="main-menu"
            icon="add"
            label="${this.t.newJourney}"
            part="newjourneybtn"
            @click="${this._addButtonTap}"
          ></app-hax-user-menu-button>
          <slot slot="post-menu" name="haxcms-site-editor-ui-post-menu"></slot>
          <app-hax-user-menu-button
            slot="post-menu"
            part="logoutbtn"
            class="logout"
            label="${this.t.logOut}"
            @click=${this._logout}
          ></app-hax-user-menu-button>
        </app-hax-user-menu>
      </app-hax-top-bar>
    `}dropEvent(e){e.preventDefault(),this.activeDrag=!1,this.activeType=null,b.waveWand(["","/",e,"hax-agent","Agent"],this.shadowRoot.querySelector("#merlin"))}dragenterEvent(e){e.preventDefault(),this.sdSearch.dragover=!0}dragoverEvent(e){e.preventDefault(),this.sdSearch.dragover=!0}dragleaveEvent(e){e.preventDefault(),this.sdSearch.dragover=!1}sdCloseEvent(e){setTimeout((()=>{this._ignoreReset=!0,this.sdSearch.value=""}),0),this.sdSearch.disabled=!1,this.sdSearch.dragover=!1,this.sdSearch.droppable=!1,this.sdSearch.droppableType=null}haxButtonOp(e){let t=e.target.getAttribute("data-event");switch(t){case"super-daemon":if(!this._ignoreReset||"click"===e.type){const t=this.sdSearch.value;"value-changed"===e.type?t&&b.waveWand([t,"*"],this.shadowRoot.querySelector("#merlin"),null):b.waveWand([t,"*"],this.shadowRoot.querySelector("#merlin"),null),this.sdSearch.value=null,this.sdSearch.disabled=!1,this.sdSearch.dragover=!1,this.sdSearch.droppable=!1,this.sdSearch.droppableType=null}this._ignoreReset=!1;break;case"super-daemon-modal":this._ignoreReset&&"click"!==e.type||(o.playSound("click"),b.open(),s.haxTray.collapsed=!1);break;case"media-program":o.playSound("click"),b.runProgram("sources"),b.open(),s.haxTray.collapsed=!1;break;case"content-edit":case"content-map":case"content-add":s.haxTray.trayDetail==t?s.haxTray.collapsed=!s.haxTray.collapsed:s.haxTray.collapsed=!1,s.haxTray.trayDetail=t;break;case"undo":s.activeHaxBody.undo();break;case"redo":s.activeHaxBody.redo();break;case"view-source":s.haxTray.trayDetail=t,s.haxTray.shadowRoot.querySelector("#view-source").openSource(),s.haxTray.collapsed=!1}}_logout(){globalThis.dispatchEvent(new CustomEvent("jwt-login-logout",{composed:!0,bubbles:!0,cancelable:!1,detail:!0})),this.__logoutUserAction=!0}_jwtLoggedIn(e){!1===e.detail&&this.__logoutUserAction&&(this.__logoutUserAction=!1,setTimeout((()=>{globalThis.location.reload()}),100))}_addPageClick(e){!this.editMode&&this.shadowRoot.querySelector("simple-toolbar-menu-item haxcms-button-add:not([hidden])")&&this.shadowRoot.querySelector("simple-toolbar-menu-item haxcms-button-add:not([hidden])").HAXCMSButtonClick()}updateAvailableButtons(){this.shadowRoot&&setTimeout((()=>{globalThis.appSettings&&globalThis.appSettings.backText&&(this.backText=globalThis.appSettings.backText);[{varPath:"deleteNodePath",selector:"#deletebutton"},{varPath:"saveNodePath",selector:"#editbutton"},{varPath:"createNodePath",selector:"#addbutton"},{varPath:"createNodePath",selector:"#addbuttonchild"},{varPath:"createNodePath",selector:"#duplicatebutton"}].forEach((e=>{globalThis.appSettings&&globalThis.appSettings[e.varPath]&&null!=globalThis.appSettings[e.varPath]&&""!=globalThis.appSettings[e.varPath]&&"null"!=globalThis.appSettings[e.varPath]&&(e.dep?null!=globalThis.appSettings[e.dep]&&""!=globalThis.appSettings[e.dep]&&"null"!=globalThis.appSettings[e.dep]&&this.shadowRoot.querySelector(e.selector).removeAttribute("hidden"):this.shadowRoot.querySelector(e.selector).removeAttribute("hidden"))}))}),100)}firstUpdated(t){super.firstUpdated&&super.firstUpdated(t),this.shadowRoot.querySelectorAll("[data-super-daemon-path]").forEach((e=>{b.defineOption({title:e.getAttribute("data-super-daemon-label"),icon:e.getAttribute("data-super-daemon-icon"),tags:["page","operation","command","add","create"],value:{target:e},context:"CMS",eventName:"super-daemon-element-click",path:e.getAttribute("data-super-daemon-path")})})),this.sdSearch=this.shadowRoot.querySelector("super-daemon-search"),b.wandTarget=this.shadowRoot.querySelector("#merlin"),b.defineOption({title:this.t.save,icon:"icons:save",tags:["CMS","save","page","operation","command"],value:{target:this,method:"_editButtonTap"},context:"HAX",eventName:"super-daemon-element-method",path:"CMS/action/save"}),b.defineOption({title:this.t.insights,icon:"hax:clipboard-pulse",tags:["CMS","insights","data","operation"],value:{target:this,method:"_insightsButtonTap"},context:"CMS",eventName:"super-daemon-element-method",path:"CMS/site/insights"}),b.defineOption({title:this.t.edit,icon:"hax:page-edit",tags:["CMS","edit","page","operation","command"],value:{target:this,method:"_editButtonTap"},context:"CMS",eventName:"super-daemon-element-method",path:"CMS/action/edit"}),b.defineOption({title:this.t.siteSettings,icon:"hax:site-settings",tags:["CMS","site","settings","operation","command","theme","seo","author"],value:{target:this,method:"_manifestButtonTap",args:[{target:this.shadowRoot.querySelector("#manifestbtn")}]},context:"CMS",eventName:"super-daemon-element-method",path:"CMS/action/site/settings"}),b.defineOption({title:this.t.themeSettings,icon:"hax:site-settings",tags:["CMS","site","settings","operation","command","theme","seo","author"],value:{target:this,method:"_manifestButtonTap",args:[{target:this.shadowRoot.querySelector("#manifestbtn")}]},context:"CMS",eventName:"super-daemon-element-method",path:"CMS/action/site/settings/theme"}),b.defineOption({title:this.t.seoSettings,icon:"hax:site-settings",tags:["CMS","site","settings","operation","command","theme","seo","search","engine"],value:{target:this,method:"_manifestButtonTap",args:[{target:this.shadowRoot.querySelector("#manifestbtn")}]},context:"CMS",eventName:"super-daemon-element-method",path:"CMS/action/site/settings/seo"}),b.defineOption({title:this.t.authorSettings,icon:"hax:site-settings",tags:["CMS","site","settings","operation","command","theme","author"],value:{target:this,method:"_manifestButtonTap",args:[{target:this.shadowRoot.querySelector("#manifestbtn")}]},context:"CMS",eventName:"super-daemon-element-method",path:"CMS/action/site/settings/author"}),b.defineOption({title:this.t.shareSite,icon:"social:share",tags:["CMS","share"],value:{target:this,method:"_shareButtonTap"},context:["logged-in","CMS","HAX"],eventName:"super-daemon-element-method",path:"CMS/action/share"}),b.defineOption({title:this.t.newJourney,icon:"add",tags:["CMS","create","new site"],value:{target:this,method:"_addButtonTap"},context:"CMS",eventName:"super-daemon-element-method",path:"CMS/action/create-site"}),b.defineOption({title:this.t.logOut,icon:"add",tags:["CMS","user","logout"],value:{target:this,method:"_logout"},context:["logged-in","CMS"],eventName:"super-daemon-element-method",path:"CMS/user/logout"}),b.defineOption({title:"Dark mode toggle",icon:"device:brightness-medium",tags:["CMS","dark mode"],value:{target:this.shadowRoot.querySelector("haxcms-darkmode-toggle"),method:"toggle"},voice:"(toggle) dark mode",eventName:"super-daemon-element-method",path:"CMS/action/darkMode"}),b.defineOption({title:"Sound toggle",icon:"av:volume-up",tags:["CMS","sound"],value:{target:this.shadowRoot.querySelector(".soundToggle")},eventName:"super-daemon-element-click",path:"CMS/action/sound"}),b.defineOption({title:this.t.outlineDesigner,icon:"hax:site-map",tags:["CMS","outline","designer","site outline","operation","command"],value:{target:this.shadowRoot.querySelector("#outlinebutton")},context:["CMS"],eventName:"super-daemon-element-click",path:"CMS/action/outline"}),b.defineOption({title:"Load HAXSchema",icon:"hax:hax2022",tags:["Developer","schema","load","demo","testing"],eventName:"super-daemon-run-program",path:">hax/loadElement",context:[">"],value:{name:"Load HAXSchema",context:">",program:async(e,t)=>{const i=globalThis.WCAutoload.requestAvailability();let o=[];return Object.keys(i.registry.list).forEach((async t=>{let a="hax:hax2022";if(globalThis.customElements.get(t)&&globalThis.customElements.get(t).haxProperties&&globalThis.customElements.get(t).haxProperties.gizmo&&(a=globalThis.customElements.get(t).haxProperties.gizmo.icon),""==e||t.includes(e)){let e={};e[t]=i.registry.list[t],o.push({title:t,icon:a,tags:["schema"],value:{target:globalThis.HaxStore.instance,method:"_handleDynamicImports",args:[e,globalThis.HaxStore.instance.haxAutoloader]},eventName:"super-daemon-element-method",context:[">",">hax/loadElement/"+t],path:">hax/loadElement/"+t})}})),o}}}),b.defineOption({title:"Change theme temporarily",icon:"image:style",tags:["Developer","theme"],eventName:"super-daemon-run-program",path:">settings/theme",context:[">"],more:e`<span
        >Change theme just for the current browsing session</span
      >`,voice:"change theme (temporarily)",value:{name:"Change theme",context:">",program:async(e,t)=>{let i=[];return["clean-one","clean-two","learn-two-theme","polaris-theme","polaris-invent-theme","polaris-flex-theme","ddd-brochure-theme","collections-theme","training-theme","bootstrap-theme","outline-player","haxor-slevin"].forEach((async t=>{(""==e||t.includes(e))&&i.push({title:t.replace("-theme","").replace("-"," "),icon:"image:style",tags:["theme"],value:{target:globalThis.HAXCMS,method:"setTheme",args:[t]},eventName:"super-daemon-element-method",context:[">",">settings/theme/"+t],path:">settings/theme/"+t})})),i}}}),b.defineOption({title:"HAX Labs",icon:"hax:hax2022",tags:["Developer","labs","experiments"],eventName:"super-daemon-element-method",path:">hax/labs",context:[">"],value:{target:this,method:"enableLabExperiments",args:[]}}),b.defineOption({title:"Go to site",icon:"hax:hax2022",tags:["Developer","change","sites","administration"],eventName:"super-daemon-run-program",path:"/hax/changeSite",context:["CMS"],value:{name:"Go to site",context:"CMS",program:async(e,t)=>{let i=[];return await fetch("./../../system/api/listSites").then((e=>e.ok?e.json():[])).then((t=>{t.data&&t.data.items.length>0&&t.data.items.forEach((async t=>{(""==e||t.metadata.site&&t.metadata.site.name&&t.metadata.site.name.includes(e)&&o.manifest.metadata.site.name!=t.metadata.site.name)&&i.push({title:t.title,icon:t.metadata.theme.variables.icon,tags:["site",t.description],value:{target:this,method:"goToLocation",args:[t.slug]},eventName:"super-daemon-element-method",context:["/","/hax/changeSite/"+t.metadata.site.name],path:"/hax/changeSite/"+t.metadata.site.name})}))})),i}}}),this.updateAvailableButtons(),this.dispatchEvent(new CustomEvent("haxcms-load-user-data",{bubbles:!0,composed:!0,cancelable:!1,detail:!0}))}enableLabExperiments(){import("../../../video-player/lib/lecture-player.js"),import("../ui-components/magic/site-ai-chat.js")}goToLocation(e){globalThis.location=e}updated(e){super.updated&&super.updated(e),e.forEach(((e,t)=>{"userMenuOpen"===t&&void 0!==e&&(this.userMenuOpen?this.rpgHat="edit":this.rpgHat="none"),"responsiveSize"===t&&(["xs","sm","md"].includes(this[t])?(this.editMode?this.__editText=this.t.save:this.__editText=this.t.edit,this.t.configureBlock="Configure",this.t.addBlock="Block",this.t.findMedia="Media",this.t.pageOutline="Outline",this.t.viewSource="Source"):(this.editMode?this.__editText=this.t.save:this.__editText=this.t.edit,this.t.configureBlock="Configure block",this.t.addBlock="Add block",this.t.findMedia="Find media",this.t.pageOutline="Page outline",this.t.viewSource="View source")),"editMode"==t&&(this.editMode?this.rpgHat="construction":this.rpgHat="none",void 0!==e&&b.close(),this._editModeChanged(this[t],e),this.dispatchEvent(new CustomEvent("edit-mode-changed",{detail:this[t]}))),"manifestEditMode"==t&&(this._manifestEditModeChanged(this[t],e),this.dispatchEvent(new CustomEvent("manifest-edit-mode-changed",{detail:this[t]})))}))}_redoChanged(e){this.canRedo=e.detail.value}_undoChanged(e){this.canUndo=e.detail.value}static get properties(){return{...super.properties,userName:{type:String,attribute:"user-name"},activeDrag:{type:Boolean},activeType:{type:String},activeNode:{type:Object},activeTagName:{type:String},canUndo:{type:Boolean,attribute:"can-undo"},canRedo:{type:Boolean,attribute:"can-redo"},rpgHat:{type:String},userPicture:{type:String,attribute:"user-picture"},userMenuOpen:{type:Boolean},soundIcon:{type:String},darkMode:{type:Boolean,reflect:!0,attribute:"dark-mode"},backLink:{type:String},backText:{type:String},__editIcon:{type:String},__editText:{type:String},painting:{type:Boolean,reflect:!0},pageAllowed:{type:Boolean,attribute:"page-allowed",reflect:!0},editMode:{type:Boolean,reflect:!0,attribute:"edit-mode"},manifestEditMode:{type:Boolean,attribute:"manifest-edit-mode",reflect:!0},activeTitle:{type:String,attribute:"active-title"},manifest:{type:Object},icon:{type:String}}}connectedCallback(){super.connectedCallback(),n((e=>{o.userData&&(this.userName=l(o.userData.userName),this.userPicture=l(o.userData.userPicture),this.updateAvailableButtons()),this.__disposer.push(e)})),n((e=>{this.editMode=l(o.editMode),x.writeMemory("editMode",this.editMode),this.__disposer.push(e)})),n((e=>{this.manifest=l(o.manifest),this.icon="hax:site-settings",this.__disposer.push(e)})),n((e=>{const t=l(o.activeItem);this.updateAvailableButtons(),t&&t.id&&!t._internalRoute?(this.activeTitle=t.title,this.pageAllowed=!0):this.pageAllowed=!1,this.__disposer.push(e)}))}disconnectedCallback(){for(var e in this.__disposer)this.__disposer[e].dispose();super.disconnectedCallback()}_editButtonTap(e){if(this.editMode&&"view-source"===s.haxTray.trayDetail&&!globalThis.confirm(this.t.confirmHtmlSourceExit))return!1;o.playSound("click"),this.editMode=!this.editMode,this.editMode||this.dispatchEvent(new CustomEvent("haxcms-save-node",{bubbles:!0,composed:!0,cancelable:!1,detail:o.activeItem})),globalThis.dispatchEvent(new CustomEvent("simple-modal-hide",{bubbles:!0,cancelable:!0,detail:{}}))}_insightsButtonTap(e){o.playSound("click");const t=globalThis.document.createElement("haxcms-site-insights"),i=new CustomEvent("simple-modal-show",{bubbles:!0,composed:!0,cancelable:!1,detail:{title:this.t.insights,styles:{"--simple-modal-titlebar-background":"black","--simple-modal-titlebar-color":"var(--hax-ui-background-color)","--simple-modal-width":"94vw","--simple-modal-min-width":"300px","--simple-modal-z-index":"100000000","--simple-modal-height":"94vh","--simple-modal-min-height":"300px","--simple-modal-titlebar-height":"80px"},elements:{content:t},invokedBy:this.shadowRoot.querySelector("#insightsbutton"),clone:!1,modal:!1}});globalThis.dispatchEvent(i)}async _cancelButtonTap(e){if(await s.activeHaxBody.haxToContent()!=this._originalContent&&!globalThis.confirm(this.t.unsavedChangesWillBeLostIfSelectingOkAreYouSure))return!1;this.editMode=!1,o.playSound("error"),this.dispatchEvent(new CustomEvent("hax-cancel",{bubbles:!0,composed:!0,cancelable:!1,detail:e.detail})),globalThis.dispatchEvent(new CustomEvent("simple-modal-hide",{bubbles:!0,cancelable:!0,detail:{}}))}_deleteButtonTap(e){o.playSound("click");let t=globalThis.document.createElement("span");t.innerHTML=`"${o.activeItem.title}" will be removed from the outline but its content stays on the file system.`;let i=globalThis.document.createElement("button");i.appendChild(globalThis.document.createTextNode("Confirm")),i.classList.add("hax-modal-btn"),i.addEventListener("click",this._deleteActive.bind(this));let a=globalThis.document.createElement("button");a.appendChild(globalThis.document.createTextNode("cancel")),a.addEventListener("click",(()=>o.playSound("error"))),a.setAttribute("dialog-dismiss","dialog-dismiss"),a.classList.add("hax-modal-btn"),a.classList.add("cancel");let s=globalThis.document.createElement("span");s.appendChild(i),s.appendChild(a);const n=new CustomEvent("simple-modal-show",{bubbles:!0,composed:!0,cancelable:!1,detail:{title:"Are you sure you want to delete this page?",styles:{"--simple-modal-titlebar-background":"black","--simple-modal-titlebar-color":"var(--hax-ui-background-color)","--simple-modal-width":"25vw","--simple-modal-min-width":"300px","--simple-modal-z-index":"100000000","--simple-modal-height":"15vh","--simple-modal-min-height":"300px","--simple-modal-titlebar-height":"80px"},elements:{content:t,buttons:s},invokedBy:this.shadowRoot.querySelector("#deletebutton"),clone:!1,modal:!0}});globalThis.dispatchEvent(n)}_deleteActive(e){o.playSound("click");const t=new CustomEvent("haxcms-delete-node",{bubbles:!0,composed:!0,cancelable:!1,detail:{item:o.activeItem}});this.dispatchEvent(t)}_shareButtonTap(e){o.playSound("click");const t=new CustomEvent("simple-modal-show",{bubbles:!0,composed:!0,cancelable:!1,detail:{title:this.t.shareSite,styles:{"--simple-modal-titlebar-background":"black","--simple-modal-titlebar-color":"var(--hax-ui-background-color)","--simple-modal-width":"55vw","--simple-modal-min-width":"300px","--simple-modal-z-index":"100000000","--simple-modal-height":"50vh","--simple-modal-min-height":"300px","--simple-modal-titlebar-height":"80px"},elements:{content:globalThis.document.createElement("haxcms-share-dialog")},invokedBy:this.shadowRoot.querySelector("#sharebutton"),clone:!1,modal:!1}});globalThis.dispatchEvent(t)}_outlineButtonTap(e){o.playSound("click");const t=new CustomEvent("simple-modal-show",{bubbles:!0,composed:!0,cancelable:!1,detail:{title:this.t.outlineDesigner,styles:{"--simple-modal-titlebar-background":"black","--simple-modal-titlebar-color":"var(--hax-ui-background-color)","--simple-modal-z-index":"100000000","--simple-modal-titlebar-height":"80px","--simple-modal-width":"85vw","--simple-modal-max-width":"85vw","--simple-modal-height":"85vh","--simple-modal-max-height":"85vh"},elements:{content:globalThis.document.createElement("haxcms-outline-editor-dialog")},invokedBy:this.shadowRoot.querySelector("#outlinebutton"),clone:!1,modal:!0}});globalThis.dispatchEvent(t)}_addButtonTap(){o.playSound("click"),setTimeout((()=>{globalThis.location=this.backLink+"createSite-step-1"}),100)}_manifestButtonTap(e){o.playSound("click"),globalThis.dispatchEvent(new CustomEvent("simple-modal-hide",{bubbles:!0,cancelable:!0,detail:{}})),import("./haxcms-site-dashboard.js").then((()=>{globalThis.dispatchEvent(new CustomEvent("simple-modal-show",{bubbles:!0,composed:!0,cancelable:!1,detail:{title:this.t.editSettings,styles:{"--simple-modal-titlebar-background":"black","--simple-modal-titlebar-color":"var(--hax-ui-background-color)","--simple-modal-z-index":"100000000","--simple-modal-titlebar-height":"80px","--simple-modal-width":"85vw","--simple-modal-max-width":"85vw","--simple-modal-height":"85vh","--simple-modal-max-height":"85vh"},elements:{content:globalThis.document.createElement("haxcms-site-dashboard")},invokedBy:this.shadowRoot.querySelector("#manifestbtn"),clone:!1,modal:!0}})),setTimeout((()=>{globalThis.dispatchEvent(new CustomEvent("haxcms-load-site-dashboard",{bubbles:!0,composed:!0,cancelable:!1,detail:e.target}))}),0)}))}_editModeChanged(e,t){e?(setTimeout((async()=>{this._originalContent=await s.activeHaxBody.haxToContent()}),100),this.__editIcon="icons:save",this.__editText=this.t.save,b.appendContext("HAX"),b.removeContext("CMS")):(this.__editIcon="hax:page-edit",this.__editText=this.t.edit,b.appendContext("CMS"),b.removeContext("HAX")),void 0!==t&&(o.editMode=e,e&&(s.haxTray.collapsed=!1))}_outlineEditModeChanged(e,t){this.dispatchEvent(new CustomEvent("haxcms-outline-edit-mode-changed",{bubbles:!0,composed:!0,cancelable:!1,detail:e}))}_manifestEditModeChanged(e,t){this.dispatchEvent(new CustomEvent("haxcms-manifest-edit-mode-changed",{bubbles:!0,composed:!0,cancelable:!1,detail:e}))}}customElements.define(HAXCMSSiteEditorUI.tag,HAXCMSSiteEditorUI);export{HAXCMSSiteEditorUI};