"use strict";

exports.__esModule = true;
exports.default = void 0;
var _tslib = require("tslib");
var _react = _interopRequireWildcard(require("react"));
var _dayjs = _interopRequireDefault(require("dayjs"));
var _view = _interopRequireDefault(require("../../view"));
var _embedPicker = _interopRequireDefault(require("../../time-picker/embed-picker"));
var _dateIndicator = _interopRequireDefault(require("../date-indicator"));
var _datePicker = _interopRequireDefault(require("./date-picker"));
var _modeSwitch = _interopRequireDefault(require("../mode-switch"));
var _useToggle2 = _interopRequireDefault(require("../../utils/hooks/use-toggle"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var DateTimePicker = function (props) {
  var _props$prefix = props.prefix,
    prefix = _props$prefix === void 0 ? 'mt-' : _props$prefix,
    defaultValue = props.defaultValue,
    value = props.value,
    _props$dateSelectTip = props.dateSelectTip,
    dateSelectTip = _props$dateSelectTip === void 0 ? '选择具体时间' : _props$dateSelectTip,
    _props$timeSelectTip = props.timeSelectTip,
    timeSelectTip = _props$timeSelectTip === void 0 ? '返回选择日期' : _props$timeSelectTip,
    disableDate = props.disableDate,
    validRange = props.validRange,
    onChange = props.onChange,
    others = (0, _tslib.__rest)(props, ["prefix", "defaultValue", "value", "dateSelectTip", "timeSelectTip", "disableDate", "validRange", "onChange"]);
  var _useToggle = (0, _useToggle2.default)('date', 'time'),
    mode = _useToggle[0],
    toggleMode = _useToggle[1].toggle;
  return /*#__PURE__*/(0, _react.createElement)(_view.default, others, /*#__PURE__*/(0, _react.createElement)(_dateIndicator.default, {
    highlight: mode === 'date' ? 0 : 1,
    values: [(0, _dayjs.default)(value).format('YYYY-MM-DD'), (0, _dayjs.default)(value).format('HH:mm:ss')]
  }), mode === 'date' ? /*#__PURE__*/(0, _react.createElement)(_datePicker.default, {
    defaultValue: defaultValue,
    value: value,
    validRange: validRange,
    onChange: function handleDateChange(d) {
      var curTime = (0, _dayjs.default)(value);
      var newTime = (0, _dayjs.default)(d).hour(curTime.hour()).minute(curTime.minute()).second(curTime.second());
      onChange(newTime.toDate());
    }
  }) : /*#__PURE__*/(0, _react.createElement)(_embedPicker.default, {
    defaultValue: defaultValue,
    value: value,
    onChange: function handleTimeChange(d) {
      var curTime = (0, _dayjs.default)(value);
      var newTime = (0, _dayjs.default)(d).year(curTime.year()).month(curTime.month()).date(curTime.date());
      onChange(newTime.toDate());
    }
  }), /*#__PURE__*/(0, _react.createElement)(_modeSwitch.default, {
    defaultText: dateSelectTip,
    reverseText: timeSelectTip,
    value: mode === 'date' ? 'default' : 'reverse',
    onChange: toggleMode
  }));
};
var _default = DateTimePicker;
exports.default = _default;