'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-7a477838.js');
const text = require('./text-3157012b.js');
const typographyTimeVariation_enum = require('./typography-time-variation.enum-bce1d87e.js');

const TypographyTime = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.formatedDate = undefined;
        this.datetime = undefined;
        this.afDateTime = undefined;
        this.afVariation = typographyTimeVariation_enum.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 text._t.time.days_ago(days);
        }
        if (distance < oneDay) {
            return days === 0 ? text._t.today : text._t.time.in_days(days);
        }
    }
    formatDate(dateToFormat) {
        const date = new Date(dateToFormat);
        switch (this.afVariation) {
            case typographyTimeVariation_enum.TypographyTimeVariation.PRIMARY:
                this.formatedDate = this.primaryFormat(date);
                break;
            case typographyTimeVariation_enum.TypographyTimeVariation.PRETTY:
                this.formatedDate = this.prettyFormat(date);
                break;
            case typographyTimeVariation_enum.TypographyTimeVariation.DISTANCE:
                this.formatedDate = this.distanceFormat(date);
                break;
        }
        this.datetime = this.primaryFormat(date);
    }
    componentWillLoad() {
        this.formatDate(this.afDateTime);
    }
    render() {
        return (index.h("time", { key: 'd078e4f1cdc123ea93af44910f116ad539a2088e', dateTime: this.datetime, class: "digi-typography-time" }, this.formatedDate));
    }
    static get watchers() { return {
        "afDateTime": ["formatDate"]
    }; }
};

exports.digi_typography_time = TypographyTime;
