import{LitElement as t,html as e}from"../../lit/index.js";import"../es-global-bridge/es-global-bridge.js";
/**
 * @license
 * Copyright (c) 2016 Abdón Rodríguez Davila (@abdonrd). All rights reserved.
 * This code may only be used under the MIT style license found at https://abdonrd.github.io/LICENSE.txt
 */class MomentElement extends t{render(){return e` ${this.output} `}static get tag(){return"moment-element"}static get properties(){return{datetime:{type:String},inputFormat:{type:String,attribute:"input-format"},outputFormat:{type:String,attribute:"output-format"},from:{type:String},to:{type:String},output:{type:String},libraryLoaded:{type:Boolean}}}constructor(){super(),this.windowControllers=new AbortController,this.datetime=new Date,this.inputFormat="",this.outputFormat="",this.from="",this.to="";const t=new URL("./lib/moment/moment.min.js",import.meta.url).href;globalThis.addEventListener("es-bridge-moment-loaded",this._momentLoaded.bind(this),{signal:this.windowControllers.signal}),globalThis.ESGlobalBridge.requestAvailability().load("moment",t)}updated(t){t.forEach(((t,e)=>{if(["output"].includes(e)){let t=`${e.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g,"$1-$2").toLowerCase()}-changed`;this.dispatchEvent(new CustomEvent(t,{detail:{value:this[e]}}))}["datetime","inputFormat","outputFormat","from","to","libraryLoaded"].includes(e)&&(this.output=this._computeOutput(this.datetime,this.inputFormat,this.outputFormat,this.from,this.to,this.libraryLoaded))}))}disconnectedCallback(){this.windowControllers.abort(),super.disconnectedCallback()}_momentLoaded(){this.libraryLoaded=!0}_computeOutput(t,e,o,i,r,n){if(n){var m=e?moment(t,e):moment(t);return o?m=m.format(o):i?m="now"===i?m.fromNow():m.from(moment(i)):r&&(m="now"===r?m.toNow():m.to(moment(r))),m}}}customElements.define(MomentElement.tag,MomentElement);export{MomentElement};