import { p as proxyCustomElement, H, h } from './p-a53686b3.js';
import { _ as _t } from './p-08cf2c0e.js';
import { T as TypographyTimeVariation } from './p-b0e88537.js';

const TypographyTime = /*@__PURE__*/ proxyCustomElement(class TypographyTime extends H {
    constructor() {
        super();
        this.__registerHost();
        this.formatedDate = undefined;
        this.datetime = undefined;
        this.afDateTime = undefined;
        this.afVariation = TypographyTimeVariation.PRIMARY;
        this.afLocale = 'default';
    }
    primaryFormat(date) {
        return date.toLocaleString(this.afLocale, {
            year: 'numeric',
            month: '2-digit',
            day: '2-digit'
        });
    }
    prettyFormat(date) {
        return date.toLocaleString(this.afLocale, {
            day: 'numeric',
            month: 'long',
            year: 'numeric'
        });
    }
    distanceFormat(date) {
        const oneDay = 1000 * 3600 * 24;
        const distance = Math.floor(Date.now() - date.getTime());
        let days = Math.floor(distance / oneDay);
        days = Math.abs(days);
        if (distance > oneDay) {
            return _t.time.days_ago(days);
        }
        if (distance < oneDay) {
            return days === 0 ? _t.today : _t.time.in_days(days);
        }
    }
    formatDate(dateToFormat) {
        const date = new Date(dateToFormat);
        switch (this.afVariation) {
            case TypographyTimeVariation.PRIMARY:
                this.formatedDate = this.primaryFormat(date);
                break;
            case TypographyTimeVariation.PRETTY:
                this.formatedDate = this.prettyFormat(date);
                break;
            case TypographyTimeVariation.DISTANCE:
                this.formatedDate = this.distanceFormat(date);
                break;
        }
        this.datetime = this.primaryFormat(date);
    }
    componentWillLoad() {
        this.formatDate(this.afDateTime);
    }
    render() {
        return (h("time", { key: 'd078e4f1cdc123ea93af44910f116ad539a2088e', dateTime: this.datetime, class: "digi-typography-time" }, this.formatedDate));
    }
    static get watchers() { return {
        "afDateTime": ["formatDate"]
    }; }
}, [2, "digi-typography-time", {
        "afDateTime": [8, "af-date-time"],
        "afVariation": [1, "af-variation"],
        "afLocale": [1, "af-locale"],
        "formatedDate": [32],
        "datetime": [32]
    }, undefined, {
        "afDateTime": ["formatDate"]
    }]);
function defineCustomElement$1() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["digi-typography-time"];
    components.forEach(tagName => { switch (tagName) {
        case "digi-typography-time":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, TypographyTime);
            }
            break;
    } });
}

const DigiTypographyTime = TypographyTime;
const defineCustomElement = defineCustomElement$1;

export { DigiTypographyTime, defineCustomElement };
