export class DateTimeFormatter {
    constructor(locale) {
        this.locale = locale;
    }
    format(value, format) {
        const date = new Date(value);
        return {
            prefix: this.formatAffix('prefix', date, format),
            value: this.formatValue(date, format),
            suffix: this.formatAffix('suffix', date, format),
        };
    }
    formatValue(date, format) {
        const options = Object.assign({}, format.options);
        if (format.prefix)
            for (const prefix of format.prefix) {
                delete options[prefix];
            }
        if (format.suffix)
            for (const suffix of format.suffix) {
                delete options[suffix];
            }
        const formatter = new Intl.DateTimeFormat(this.locale, options);
        return formatter.format(date);
    }
    formatAffix(affix, date, format) {
        const options = Object.assign({}, format.options);
        for (const option of Object.keys(options)) {
            if (option === 'hour12') {
                continue;
            }
            if ((format[affix] || []).includes(option)) {
                continue;
            }
            delete options[option];
        }
        if (Object.values(options).filter(Boolean).length === 0) {
            return;
        }
        const formatter = new Intl.DateTimeFormat(this.locale, options);
        return formatter.format(date);
    }
}
