/**
 * Copyright 2022 The Pennsylvania State University
 * @license Apache-2.0, see License.md for full text.
 */
import{LitElement as e,html as t,css as i}from"../../../../../lit/index.js";import{store as r}from"../../core/haxcms-site-store.js";import{toJS as n}from"../../../../../mobx/dist/mobx.esm.js";class SiteUuidLink extends e{static get styles(){return[i`
        :host {
          display: inline;
        }
      `]}static get tag(){return"site-uuid-link"}constructor(){super(),this.uuid=null}render(){return t`
      <a href="${this.getLinkFromUUID(this.uuid)}" @click="${this.testOpen}">
        ${this.getTitleFromUUID(this.uuid)}
      </a>
    `}testOpen(e){if(this._haxstate)return e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation(),!1}getLinkFromUUID(e){if(e&&r.findItem(e)){return n(r.findItem(e)).slug}return""}getTitleFromUUID(e){if(e&&r.findItem(e)){return n(r.findItem(e)).title}return""}static get properties(){return{uuid:{type:String}}}static get haxProperties(){return{canScale:!1,canEditSource:!1,gizmo:{title:"HAX link",description:"A link to a specific resource in the site your working on.",icon:"icons:link",color:"grey",tags:["Other","haxcms","content","remote","reference","url","resource"],handles:[{type:"inline",text:"term"}],meta:{author:"HAXTheWeb core team"}},settings:{configure:[{property:"uuid",title:"Item",description:"Item to render for the link / title data",inputMethod:"textfield"}]}}}haxHooks(){return{editModeChanged:"haxeditModeChanged",activeElementChanged:"haxactiveElementChanged",setupActiveElementForm:"haxsetupActiveElementForm"}}haxeditModeChanged(e){this._haxstate=e}haxactiveElementChanged(e,t){t&&(this._haxstate=t)}haxsetupActiveElementForm(e){if(globalThis.HAXCMS){const i=r.getManifestItems(!0);var t=[{text:"Select page",value:null}];i.forEach((e=>{if(e.id!=this.itemId){let r=e,n="- ";for(;r&&null!=r.parent;)r=i.find((e=>e.id==r.parent)),r&&(n="--"+n);t.push({text:n+e.title,value:e.id})}})),e.settings.configure.forEach(((i,r)=>{"uuid"===i.property&&(e.settings.configure[r].inputMethod="select",e.settings.configure[r].itemsList=t)}))}}}customElements.define(SiteUuidLink.tag,SiteUuidLink);export{SiteUuidLink};