import{LocalizeController as e}from"./chunk.2A3352EO.js";import{ShoelaceElement as t}from"./chunk.Z7XDKKOD.js";import{__decorateClass as i}from"./chunk.6M63UXML.js";import{html as o}from"../../../../lit/index.js";import{property as m,state as n}from"../../../../lit/decorators.js";var r=[{max:276e4,value:6e4,unit:"minute"},{max:72e6,value:36e5,unit:"hour"},{max:5184e5,value:864e5,unit:"day"},{max:24192e5,value:6048e5,unit:"week"},{max:28512e6,value:2592e6,unit:"month"},{max:1/0,value:31536e6,unit:"year"}],a=class extends t{constructor(){super(...arguments),this.localize=new e(this),this.isoTime="",this.relativeTime="",this.titleTime="",this.date=new Date,this.format="long",this.numeric="auto",this.sync=!1}disconnectedCallback(){super.disconnectedCallback(),clearTimeout(this.updateTimeout)}render(){const e=new Date,t=new Date(this.date);if(isNaN(t.getMilliseconds()))return this.relativeTime="",this.isoTime="","";const i=t.getTime()-e.getTime(),{unit:m,value:n}=r.find((e=>Math.abs(i)<e.max));if(this.isoTime=t.toISOString(),this.titleTime=this.localize.date(t,{month:"long",year:"numeric",day:"numeric",hour:"numeric",minute:"numeric",timeZoneName:"short"}),this.relativeTime=this.localize.relativeTime(Math.round(i/n),m,{numeric:this.numeric,style:this.format}),clearTimeout(this.updateTimeout),this.sync){let e;e=getTimeUntilNextUnit("minute"===m?"second":"hour"===m?"minute":"day"===m?"hour":"day"),this.updateTimeout=window.setTimeout((()=>this.requestUpdate()),e)}return o` <time datetime=${this.isoTime} title=${this.titleTime}>${this.relativeTime}</time> `}};function getTimeUntilNextUnit(e){const t={second:1e3,minute:6e4,hour:36e5,day:864e5}[e];return t-Date.now()%t}i([n()],a.prototype,"isoTime",2),i([n()],a.prototype,"relativeTime",2),i([n()],a.prototype,"titleTime",2),i([m()],a.prototype,"date",2),i([m()],a.prototype,"format",2),i([m()],a.prototype,"numeric",2),i([m({type:Boolean})],a.prototype,"sync",2);export{a as SlRelativeTime};