"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get EDITOR_TYPE () {
        return EDITOR_TYPE;
    },
    get IntlDateEditor () {
        return IntlDateEditor;
    }
});
const _textEditor = require("../textEditor");
const _dateTime = require("../../helpers/dateTime");
const _console = require("../../helpers/console");
const _templateLiteralTag = require("../../helpers/templateLiteralTag");
const _mixed = require("../../helpers/mixed");
const EDITOR_TYPE = 'intl-date';
class IntlDateEditor extends _textEditor.TextEditor {
    static get EDITOR_TYPE() {
        return EDITOR_TYPE;
    }
    init() {
        super.init();
        this.hot.addHook('afterSetTheme', (themeName, firstRun)=>{
            if (!firstRun) {
                this.close();
            }
        });
    }
    /**
   * Create data picker instance.
   */ createElements() {
        super.createElements('input');
        this.TEXTAREA.setAttribute('type', 'date');
    }
    /**
   * Set the value of the editor.
   *
   * @param {*} value The value to set.
   */ setValue(value) {
        if ((0, _mixed.isEmpty)(value)) {
            value = this.cellProperties.defaultDate;
        }
        if (!(0, _dateTime.isValidISODate)(value)) {
            (0, _console.warn)((0, _templateLiteralTag.toSingleLine)`IntlDateEditor: value must be in ISO date format ("YYYY-MM-DD")\x20
        required by the native date input. Received:`, value);
            return;
        }
        super.setValue(value);
    }
    /**
   * Sets focus state on the select element.
   */ focus() {
        // For IME editor textarea element must be focused using ".select" method.
        // Using ".focus" browser automatically scroll into the focused element which
        // is undesired effect.
        this.TEXTAREA.select();
    }
    /**
   * Open editor.
   */ open() {
        super.open();
        // Prevents "Failed to execute 'showPicker' on 'HTMLInputElement': HTMLInputElement::showPicker() requires a user gesture." errors
        // when running tests or calling the method directly out of the event-loop cycle.
        try {
            this.TEXTAREA.showPicker();
        } catch  {} // eslint-disable-line no-empty
    }
}
