"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MobileTimeControlRenderer = exports.MobileDatetimeControlRenderer = exports.MobileDateControlRenderer = void 0;
var tslib_1 = require("tslib");
var react_1 = tslib_1.__importDefault(require("react"));
var moment_1 = tslib_1.__importDefault(require("moment"));
var Item_1 = require("../Form/Item");
var Date_1 = tslib_1.__importDefault(require("../Form/Date"));
var date_picker_1 = tslib_1.__importDefault(require("antd-mobile/lib/date-picker"));
var MobileDateControl = /** @class */ (function (_super) {
    tslib_1.__extends(MobileDateControl, _super);
    function MobileDateControl() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    MobileDateControl.prototype.handleChange = function (value) {
        var _a = this.props, onChange = _a.onChange, format = _a.format, minTime = _a.minTime, maxTime = _a.maxTime, utc = _a.utc;
        if (!moment_1.default.isDate(value)) {
            return;
        }
        var date = moment_1.default(value);
        if (minTime && date && date.isBefore(minTime, 'second')) {
            date = minTime;
        }
        else if (maxTime && date && date.isAfter(maxTime, 'second')) {
            date = maxTime;
        }
        onChange(utc ? moment_1.default.utc(date).format(format) : date.format(format));
    };
    MobileDateControl.prototype.render = function () {
        var _a = this.props, format = _a.format, className = _a.className, cx = _a.classnames, value = _a.value, mode = _a.mode, placeholder = _a.placeholder, inputFormat = _a.inputFormat;
        var date = value;
        var formatValue = '';
        if (date) {
            var m = moment_1.default(date, format);
            date = new Date(m.valueOf());
            formatValue = m.format(inputFormat);
        }
        return (react_1.default.createElement("div", { className: cx("DateControl", className) },
            react_1.default.createElement(date_picker_1.default, { mode: mode, value: date, extra: placeholder, format: inputFormat, onOk: this.handleChange.bind(this) },
                react_1.default.createElement("span", null, date ? formatValue : placeholder))));
    };
    MobileDateControl.defaultProps = tslib_1.__assign(tslib_1.__assign({}, Date_1.default.defaultProps), { mode: 'datetime' });
    return MobileDateControl;
}(Date_1.default));
exports.default = MobileDateControl;
var MobileDateControlRenderer = /** @class */ (function (_super) {
    tslib_1.__extends(MobileDateControlRenderer, _super);
    function MobileDateControlRenderer() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    MobileDateControlRenderer.defaultProps = tslib_1.__assign(tslib_1.__assign({}, MobileDateControl.defaultProps), { mode: 'date', placeholder: '请选择日期', strictMode: false });
    MobileDateControlRenderer = tslib_1.__decorate([
        Item_1.FormItem({
            type: 'mobile-date',
            weight: -150
        })
    ], MobileDateControlRenderer);
    return MobileDateControlRenderer;
}(MobileDateControl));
exports.MobileDateControlRenderer = MobileDateControlRenderer;
var MobileDatetimeControlRenderer = /** @class */ (function (_super) {
    tslib_1.__extends(MobileDatetimeControlRenderer, _super);
    function MobileDatetimeControlRenderer() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    MobileDatetimeControlRenderer.defaultProps = tslib_1.__assign(tslib_1.__assign({}, MobileDateControl.defaultProps), { inputFormat: 'YYYY-MM-DD HH:mm', placeholder: '请选择日期以及时间', strictMode: false });
    MobileDatetimeControlRenderer = tslib_1.__decorate([
        Item_1.FormItem({
            type: 'mobile-datetime'
        })
    ], MobileDatetimeControlRenderer);
    return MobileDatetimeControlRenderer;
}(MobileDateControl));
exports.MobileDatetimeControlRenderer = MobileDatetimeControlRenderer;
var MobileTimeControlRenderer = /** @class */ (function (_super) {
    tslib_1.__extends(MobileTimeControlRenderer, _super);
    function MobileTimeControlRenderer() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    MobileTimeControlRenderer.defaultProps = tslib_1.__assign(tslib_1.__assign({}, MobileDateControl.defaultProps), { placeholder: '请选择时间', inputFormat: 'HH:mm', mode: 'time', strictMode: false });
    MobileTimeControlRenderer = tslib_1.__decorate([
        Item_1.FormItem({
            type: 'mobile-time'
        })
    ], MobileTimeControlRenderer);
    return MobileTimeControlRenderer;
}(MobileDateControl));
exports.MobileTimeControlRenderer = MobileTimeControlRenderer;
//# sourceMappingURL=./renderers/Mobile/Date.js.map
