/**
 * DevExtreme (ui/date_box/ui.date_box.strategy.native.js)
 * Version: 20.1.10
 * Build date: Fri Jan 15 2021
 *
 * Copyright (c) 2012 - 2021 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
"use strict";
var _common = require("../../core/utils/common");
var _uiDate_box = require("./ui.date_box.strategy");
var _uiDate_box2 = _interopRequireDefault(_uiDate_box);
var _support = require("../../core/utils/support");
var _array = require("../../core/utils/array");
var _ui = require("./ui.date_utils");
var _ui2 = _interopRequireDefault(_ui);
var _date_serialization = require("../../core/utils/date_serialization");
var _date_serialization2 = _interopRequireDefault(_date_serialization);
var _extend = require("../../core/utils/extend");
var _devices = require("../../core/devices");
var _devices2 = _interopRequireDefault(_devices);

function _interopRequireDefault(obj) {
    return obj && obj.__esModule ? obj : {
        "default": obj
    }
}
var NativeStrategy = _uiDate_box2.default.inherit({
    NAME: "Native",
    popupConfig: function(_popupConfig) {
        return (0, _extend.extend)({}, _popupConfig, {
            width: "auto"
        })
    },
    getParsedText: function(text, format) {
        if (!text) {
            return null
        }
        if ("datetime" === this.dateBox.option("type")) {
            return new Date(text.replace(/-/g, "/").replace("T", " ").split(".")[0])
        }
        if (this._isTextInput()) {
            return this.callBase(text, format)
        } else {
            return _ui2.default.fromStandardDateFormat(text)
        }
    },
    _isTextInput: function() {
        return "text" === this.dateBox._input().prop("type")
    },
    renderPopupContent: _common.noop,
    _getWidgetName: _common.noop,
    _getWidgetOptions: _common.noop,
    _getDateBoxType: function() {
        var type = this.dateBox.option("type");
        if ((0, _array.inArray)(type, _ui2.default.SUPPORTED_FORMATS) === -1) {
            type = "date"
        } else {
            if ("datetime" === type && !(0, _support.inputType)(type)) {
                type = "datetime-local"
            }
        }
        return type
    },
    customizeButtons: function() {
        var dropDownButton = this.dateBox.getButton("dropDown");
        if (_devices2.default.real().android && dropDownButton) {
            dropDownButton.on("click", function() {
                this.dateBox._input().get(0).click()
            }.bind(this))
        }
    },
    getDefaultOptions: function() {
        return {
            mode: this._getDateBoxType()
        }
    },
    getDisplayFormat: function(displayFormat) {
        var type = this._getDateBoxType();
        return displayFormat || _ui2.default.FORMATS_MAP[type]
    },
    renderInputMinMax: function($input) {
        $input.attr({
            min: _date_serialization2.default.serializeDate(this.dateBox.dateOption("min"), "yyyy-MM-dd"),
            max: _date_serialization2.default.serializeDate(this.dateBox.dateOption("max"), "yyyy-MM-dd")
        })
    }
});
module.exports = NativeStrategy;
