"use strict";

exports.__esModule = true;
exports.default = exports.createFormat = void 0;

var _react = _interopRequireDefault(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _Icon = _interopRequireDefault(require("../DataDisplay/Icon"));

var _reactDatepicker = _interopRequireWildcard(require("react-datepicker"));

require("react-datepicker/dist/react-datepicker.css");

var _TimePicker = _interopRequireDefault(require("./TimePicker"));

var _styles = require("@material-ui/core/styles");

var _reactIntl = require("react-intl");

var _locale = require("date-fns/locale");

var _excluded = ["value", "useTime", "useDate", "onChange", "dateFormat", "showTimeZone", "timeInputLabel", "readOnly", "showTimeSelectOnly", "metadata", "timePickerTimeZone", "error"];

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; }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();

(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};

var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};

(0, _reactDatepicker.registerLocale)("fr-CA", _locale.frCA);
(0, _reactDatepicker.registerLocale)("en-US", _locale.enUS);
(0, _reactDatepicker.registerLocale)("it-IT", _locale.it);
var useStyles = (0, _styles.makeStyles)(function (theme) {
  return {
    container: {
      display: "flex",
      flexDirection: "column"
    },
    datePickerWrapper: {
      display: "flex",
      width: "auto",
      padding: function padding(props) {
        return props.readOnly ? "0" : theme.spacing(0.3, 0.5);
      },
      border: function border(props) {
        return props.readOnly ? "none" : "1px solid ".concat(theme.palette.grey.borders);
      },
      borderRadius: theme.shape.borderRadius,
      alignItems: "center",
      backgroundColor: function backgroundColor(props) {
        return props.readOnly ? "inherit" : theme.palette.background.default;
      },
      "&:focus, &:focus-within": {
        borderRadius: theme.shape.borderRadius,
        borderColor: theme.palette.focus,
        boxShadow: "0 0 4px ".concat(theme.palette.focus),
        outline: "none"
      },
      "& .react-datepicker": {
        fontFamily: theme.fontFamily
      },
      "& .react-datepicker__input-time-container": {
        margin: theme.spacing(0.5, 0, 1, 0),
        "& .react-datepicker-time__input-container .react-datepicker-time__input": {
          margin: 0,
          padding: theme.spacing(1)
        }
      },
      "& .react-datepicker-popper": {
        zIndex: 100,
        width: theme.spacing(26)
      },
      "& .react-datepicker__input-container input": {
        fontSize: theme.typography.fontSize,
        color: theme.palette.grey.dark,
        fontFamily: theme.typography.fontFamily,
        width: "inherit",
        border: "none",
        zIndex: 100,
        backgroundColor: "inherit",
        "&:focus": {
          outline: "none"
        }
      },
      "& .react-datepicker__month-container": {
        float: "none"
      },
      "& .react-datepicker__input-time-container .react-datepicker-time__input-container .react-datepicker-time__input": {
        display: "block"
      },
      "& .react-datepicker-time__caption": {
        display: "block"
      },
      "& .react-datepicker__input-time-container .react-datepicker-time__input-container": {
        display: "block"
      }
    },
    disabled: {
      border: "1px solid ".concat(theme.palette.grey.light, " !important"),
      backgroundColor: "".concat(theme.palette.grey.light, " !important")
    },
    calendarIcon: {
      fontSize: theme.fontSize
    },
    datePickerContainer: {
      width: "80%"
    },
    iconContainer: {
      width: "20%",
      display: "flex",
      justifyContent: "flex-end"
    },
    errorInput: {
      border: "".concat(theme.spacing(0.1), " solid ").concat(theme.palette.error.main, " !important"),
      "&:focus, &:focus-within": {
        border: "".concat(theme.spacing(0.1), " solid ").concat(theme.palette.error.main, " !important"),
        boxShadow: "".concat(theme.spacing(0, 0, 0.4), " ").concat(theme.palette.error.main, " !important")
      }
    },
    errorText: {
      marginTop: theme.spacing(0.5),
      color: theme.palette.error.main,
      fontSize: theme.typography.fieldLabelSize,
      float: "left"
    }
  };
});
var AMPMLocales = ["en-US", "en-CA"];

var createFormat = function createFormat(useDate, useTime, selectedLocale) {
  if (useDate && !useTime) {
    return "P";
  } else if (useTime && !useDate) {
    if (AMPMLocales.includes(selectedLocale)) {
      return "p";
    }

    return "HH:mm";
  } else {
    if (AMPMLocales.includes(selectedLocale)) {
      return "P p";
    }

    return "P HH:mm";
  }
};

exports.createFormat = createFormat;

var WrappedDatePicker = function WrappedDatePicker(_ref) {
  var value = _ref.value,
      useTime = _ref.useTime,
      _ref$useDate = _ref.useDate,
      useDate = _ref$useDate === void 0 ? true : _ref$useDate,
      onChange = _ref.onChange,
      dateFormat = _ref.dateFormat,
      showTimeZone = _ref.showTimeZone,
      timeInputLabel = _ref.timeInputLabel,
      readOnly = _ref.readOnly,
      showTimeSelectOnly = _ref.showTimeSelectOnly,
      metadata = _ref.metadata,
      timePickerTimeZone = _ref.timePickerTimeZone,
      error = _ref.error,
      props = _objectWithoutProperties(_ref, _excluded);

  var _useIntl = (0, _reactIntl.useIntl)(),
      locale = _useIntl.locale;

  var classes = useStyles({
    readOnly: readOnly
  });
  var startDate = value ? new Date(value) : null;
  var disabledCls = (0, _classnames.default)(_defineProperty({}, classes.disabled, props.disabled));

  var updateDate = function updateDate(date, metadata) {
    if (onChange) {
      onChange(date, metadata);
    }
  };

  return /*#__PURE__*/_react.default.createElement("div", {
    className: classes.container
  }, /*#__PURE__*/_react.default.createElement("label", {
    className: (0, _classnames.default)(classes.datePickerWrapper, disabledCls, error ? classes.errorInput : null)
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: classes.datePickerContainer
  }, /*#__PURE__*/_react.default.createElement(_reactDatepicker.default, _extends({}, props, {
    dateFormat: dateFormat || createFormat(useDate, useTime, locale),
    selected: startDate,
    onChange: function onChange(date) {
      return updateDate(date, metadata);
    },
    showTimeInput: useTime != null ? useTime : false,
    useTime: useTime != null ? useTime : false,
    customTimeInput: useTime ? /*#__PURE__*/_react.default.createElement(_TimePicker.default, {
      showTimeZone: showTimeZone,
      showAMPM: AMPMLocales.includes(locale),
      requestedTimeZone: timePickerTimeZone
    }) : null,
    timeInputLabel: timeInputLabel != null ? timeInputLabel : "",
    readOnly: readOnly,
    showTimeSelectOnly: showTimeSelectOnly,
    locale: locale
  }))), !readOnly ? /*#__PURE__*/_react.default.createElement("div", {
    className: classes.iconContainer
  }, /*#__PURE__*/_react.default.createElement(_Icon.default, {
    className: classes.calendarIcon,
    id: showTimeSelectOnly ? "clock" : "calendar-date"
  })) : null), error && /*#__PURE__*/_react.default.createElement("div", {
    className: classes.errorText
  }, error));
};

__signature__(WrappedDatePicker, "useIntl{{ locale }}\nuseStyles{classes}", function () {
  return [_reactIntl.useIntl, useStyles];
});

__signature__(WrappedDatePicker, "useIntl{{ locale }}\nuseStyles{classes}", function () {
  return [_reactIntl.useIntl, useStyles];
});

var _default = WrappedDatePicker;
var _default2 = _default;
var _default3 = _default2;
exports.default = _default3;
;

(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;

  if (!reactHotLoader) {
    return;
  }

  reactHotLoader.register(useStyles, "useStyles", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/DatePicker.js");
  reactHotLoader.register(AMPMLocales, "AMPMLocales", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/DatePicker.js");
  reactHotLoader.register(createFormat, "createFormat", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/DatePicker.js");
  reactHotLoader.register(WrappedDatePicker, "WrappedDatePicker", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/DatePicker.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/DatePicker.js");
})();

;

(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();

;

(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;

  if (!reactHotLoader) {
    return;
  }

  reactHotLoader.register(useStyles, "useStyles", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/DatePicker.js");
  reactHotLoader.register(AMPMLocales, "AMPMLocales", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/DatePicker.js");
  reactHotLoader.register(createFormat, "createFormat", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/DatePicker.js");
  reactHotLoader.register(WrappedDatePicker, "WrappedDatePicker", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/DatePicker.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/DatePicker.js");
})();

;

(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();