/**
 * Copyright 2019 The Pennsylvania State University
 * @license Apache-2.0, see License.md for full text.
 */
import{css as t,LitElement as e,render as i,unsafeCSS as s,html as o}from"../../../../lit/index.js";import{HAXCMSTheme as n}from"./HAXCMSThemeWiring.js";import{ResponsiveUtilityBehaviors as r}from"../../../responsive-utility/lib/responsive-utility-behaviors.js";import{store as a}from"./haxcms-site-store.js";import{autorun as l,toJS as h}from"../../../../mobx/dist/mobx.esm.js";import"../../../simple-icon/lib/simple-icons.js";import{SimpleIconsetStore as d}from"../../../simple-icon/lib/simple-iconset.js";import{editableTableDisplayStyles as c}from"../../../editable-table/lib/editable-table-behaviors.js";import{copyToClipboard as p}from"../../../utils/utils.js";class HAXCMSLitElementTheme extends(n(r(e))){constructor(){super(),this.isSafari=void 0!==globalThis.safari,this.editMode=!1,this.isLoggedIn=!1,this.__disposer=this.__disposer?this.__disposer:[],l((t=>{this.editMode=h(a.editMode),this.__disposer.push(t)})),l((t=>{h(a.activeItemContent);this.HAXCMSThemeSettings.autoScroll&&this.shadowRoot&&this.HAXCMSThemeSettings.scrollTarget&&this.HAXCMSThemeSettings.scrollTarget.scrollIntoView&&(this.isSafari?this.HAXCMSThemeSettings.scrollTarget.scrollIntoView():setTimeout((()=>{this.HAXCMSThemeSettings.scrollTarget.scrollIntoView({behavior:"instant",block:"start",inline:"nearest"})}),0)),setTimeout((()=>{let t=this.querySelectorAll("h1,h2,h3,h4,h5,h6");t.length>0&&t.forEach((t=>{t.addEventListener("click",this.copyLink.bind(this)),t.addEventListener("pointerenter",this.hoverIntentEnter.bind(this)),t.addEventListener("pointerleave",this.hoverIntentLeave.bind(this))}))}),100),this.__disposer.push(t)}))}hoverIntentEnter(t){t.target.classList.add("haxcms-copyable")}hoverIntentLeave(t){t.target.classList.remove("haxcms-copyable")}HAXCMSGlobalStyleSheetContent(){return[t`
        .haxcms-copyable {
          background-image: url("${s(d.getIcon("icons:link"))}");
          background-position: right;
          background-repeat: no-repeat;
          background-size: 36px;
        }
      `,c]}copyLink(t){let e=t.target;e||(e=t.path[0]),!e.id&&e.parentNode&&e.parentNode.id&&(e=e.parentNode),this.isSafari?e.scrollIntoView():e.scrollIntoView({behavior:"instant",block:"start",inline:"nearest"});let i=globalThis.location.origin+globalThis.location.pathname+"#"+e.getAttribute("id");globalThis.history.pushState({},null,i),globalThis.dispatchEvent(new PopStateEvent("popstate")),p(i,"Anchor link copied!")}static get properties(){let t={};return super.properties&&(t=super.properties),{...t,isSafari:{type:Boolean,reflect:!0,attribute:"is-safari"},hexColor:{type:String,attribute:"hex-color"},color:{type:String,reflect:!0},editMode:{type:Boolean,reflect:!0,attribute:"edit-mode"},isLoggedIn:{type:Boolean,reflect:!0,attribute:"is-logged-in"},contentContainer:{type:Object},_location:{type:Object}}}static get styles(){let e=[];return super.styles&&(e=super.styles),[e,t`
        :host([edit-mode]) {
          opacity: 1;
        }
        :host([hidden]) {
          display: none;
        }
        [hidden] {
          display: none !important;
        }

        @media (prefers-reduced-motion: reduce) {
          * {
            transition: none !important;
          }
        }
        /**
        * Hide the slotted content during edit mode. This must be here to work.
        */
        :host([edit-mode]) #slot {
          display: none;
        }
        #slot {
          min-height: 50vh;
        }
      `]}firstUpdated(t){super.firstUpdated&&super.firstUpdated(t),null==this.contentContainer&&(this.contentContainer=this.shadowRoot.querySelector("#contentcontainer")),i(this.HAXCMSGlobalStyleSheetContent(),a.themeStyleElement),setTimeout((()=>{setTimeout((()=>{if(this._location&&this._location.hash){let t=this.querySelector(this._location.hash);t&&(this.isSafari?t.scrollIntoView():t.scrollIntoView({behavior:"instant",block:"start",inline:"nearest"}))}}),0);let t=this.querySelectorAll("h1,h2,h3,h4,h5,h6");t.length>0&&t.forEach((t=>{t.addEventListener("click",this.copyLink.bind(this)),t.addEventListener("pointerenter",this.hoverIntentEnter.bind(this)),t.addEventListener("pointerleave",this.hoverIntentLeave.bind(this))}))}),1500)}updated(t){super.updated&&super.updated(t),t.forEach(((t,e)=>{"_location"==e&&(this._locationChanged(this[e],t),setTimeout((()=>{if(this._location&&this._location.hash){let t=this.querySelector(this._location.hash);t&&(this.isSafari?t.scrollIntoView():t.scrollIntoView({behavior:"instant",block:"start",inline:"nearest"}))}}),0)),"color"==e&&this._colorChanged(this[e],t),"contentContainer"==e&&(this.dispatchEvent(new CustomEvent("content-container-changed",{bubbles:!0,cancelable:!0,composed:!0,detail:this[e]})),this._contentContainerChanged(this[e],t)),"isLoggedIn"==e&&this.dispatchEvent(new CustomEvent("is-logged-in-changed",{bubbles:!0,cancelable:!0,composed:!0,detail:this[e]})),"editMode"==e&&(this.dispatchEvent(new CustomEvent("edit-mode-changed",{bubbles:!0,cancelable:!0,composed:!0,detail:this[e]})),this._editModeChanged(this[e],t))}))}}export{HAXCMSLitElementTheme,t as css,s as unsafeCSS,o as html,a as store,l as autorun,h as toJS};