import{__decorate as t}from"tslib";import{DateTime as e}from"luxon";import{get as o,INVARIANT as r}from"../../locale.js";import{serializable as a,SerializableBase as s}from"../../support/Serializable.js";import{Time as n}from"../Time.js";import{settings as i}from"./FormatSettings.js";import{gcxDateTimeFormatToLuxonFormat as m}from"./_utils.js";import{TimeFormat as l}from"./formats.js";export const DEFAULT_PARSING_FORMATS=[l.ISO_8601,l.TIME_SHORT,l.TIME_LONG];export function format(...t){return d.format(...t)}export function parse(...t){return d.parse(...t)}export function esriFormatToGeocortexFormat(t){switch(t){case"short-date-short-time":case"short-date-le-short-time":case"long-month-day-year-short-time":case"day-short-month-year-short-time":case"long-date-short-time":return"t";case"short-date-short-time-24":case"short-date-le-short-time-24":case"long-month-day-year-short-time-24":case"long-date-short-time-24":case"day-short-month-year-short-time-24":return"εσρι H:mm";case"short-date-long-time":case"short-date-le-long-time":case"long-month-day-year-long-time":case"long-date-long-time":case"day-short-month-year-long-time":return"T";case"short-date-long-time-24":case"short-date-le-long-time-24":case"long-month-day-year-long-time-24":case"long-date-long-time-24":case"day-short-month-year-long-time-24":return"εσρι H:mm:ss";default:throw new Error(`Unrecognized time format constant: ${t}`)}}let c=class extends s{get defaultFormat(){return this._defaultFormat}set defaultFormat(t){this._defaultFormat=t}defaultParseFormat;locale;_defaultFormat;format(t,a){let s=a,i={};t instanceof n?s=t:i="string"==typeof t?{format:t}:t;const c=s.toDate();if(isNaN(c.getTime()))return"";const f=i.format||this.defaultFormat||l.DEFAULT,d=m(f);if("ISO-8601"===d)return s.toString();let u=i.locale||this.locale||o();u===r&&(u="en");return e.fromJSDate(c).setLocale(u).toFormat(d)}parse(t,r){let a,s=r;if(null==r?(s=t,a={}):a="string"==typeof t||Array.isArray(t)?{format:t}:t,s instanceof n)return s;if("string"!=typeof s)return new n(new Date(NaN));const i=a.format??this.defaultParseFormat??DEFAULT_PARSING_FORMATS,l=[].concat(i),c={locale:a.locale??this.locale??o()};for(const t of l){const o=m(t);if("ISO-8601"===o){const t=new n(s);if(t.isValid)return t}else{const t=e.fromFormat(s,o,c);if(t.isValid){const e=t.toJSDate();return new n(`${e.getHours().toString().padStart(2,"0")}:${e.getMinutes().toString().padStart(2,"0")}:${e.getSeconds().toString().padStart(2,"0")}`)}}}return new n(new Date(NaN))}_getSerializableProperties(){return{defaultFormat:"initial",defaultParseFormat:"initial",locale:"initial"}}};c=t([a],c);export{c as TimeFormatter};let f=class extends c{get defaultFormat(){return i.timeFormat}set defaultFormat(t){i.timeFormat=t}};f=t([a],f);const d=new f;export const settings=d;