import{makeFormatter as t}from"./utils.js";const e=new WeakMap;export default class ExtendedTimeElement extends HTMLElement{static get observedAttributes(){return["datetime","day","format","lang","hour","minute","month","second","title","weekday","year","time-zone-name"]}connectedCallback(){const t=this.getFormattedTitle();t&&!this.hasAttribute("title")&&this.setAttribute("title",t);const e=this.getFormattedDate();e&&(this.textContent=e)}attributeChangedCallback(t,i,r){const n=this.getFormattedTitle();if("datetime"===t){const t=Date.parse(r);isNaN(t)?e.delete(this):e.set(this,new Date(t))}const a=this.getFormattedTitle(),s=this.getAttribute("title");"title"===t||!a||s&&s!==n||this.setAttribute("title",a);const o=this.getFormattedDate();o&&(this.textContent=o)}get date(){return e.get(this)}getFormattedTitle(){const t=this.date;if(!t)return;const e=i();if(e)return e.format(t);try{return t.toLocaleString()}catch(e){if(e instanceof RangeError)return t.toString();throw e}}getFormattedDate(){}}const i=t({day:"numeric",month:"short",year:"numeric",hour:"numeric",minute:"2-digit",timeZoneName:"short"});