import { r as registerInstance, h } from './index-148a7577.js';
import { _ as _t } from './text-26e02c8d.js';
import { T as TypographyTimeVariation } from './typography-time-variation.enum-34c830ef.js';

const TypographyTime = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        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: '996c32b9f71d80f7a2362b90d8bb153627ad4645', dateTime: this.datetime, class: "digi-typography-time" }, this.formatedDate));
    }
    static get watchers() { return {
        "afDateTime": ["formatDate"]
    }; }
};

export { TypographyTime as digi_typography_time };
