'use strict';

var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var editorCommon = require('@uidu/editor-common');
var FieldDate = require('@uidu/field-date');
var Form = require('@uidu/form');
var theme = require('@uidu/theme');
var React = require('react');
var ReactDOM = require('react-dom');
var main = require('./main-855e1efa.cjs.dev.js');
var jsxRuntime = require('react/jsx-runtime');
require('@babel/runtime/helpers/classCallCheck');
require('@babel/runtime/helpers/createClass');
require('@babel/runtime/helpers/callSuper');
require('@babel/runtime/helpers/inherits');
require('@babel/runtime/helpers/defineProperty');
require('@atlaskit/icon/glyph/chevron-down');
require('@atlaskit/icon/glyph/editor/align-center');
require('@atlaskit/icon/glyph/editor/align-left');
require('@atlaskit/icon/glyph/editor/align-right');
require('styled-components');
require('prosemirror-state');
require('@uidu/adf-schema');
require('@babel/runtime/helpers/toConsumableArray');
require('./withAnalytics-f64c1c58.cjs.dev.js');
require('./index-742099c4.cjs.dev.js');
require('@uidu/editor-json-transformer');
require('prosemirror-commands');
require('prosemirror-model');
require('prosemirror-transform');
require('prosemirror-utils');
require('prosemirror-view');
require('@uidu/editor-common/selection');
require('@uidu/adf-utils');
require('@uidu/mentions');
require('@uidu/editor-common/utils');
require('@babel/runtime/helpers/asyncToGenerator');
require('@babel/runtime/regenerator');
require('@babel/runtime/helpers/typeof');
require('@uidu/prosemirror-utils');
require('prosemirror-keymap');
require('prosemirror-history');
require('@uidu/editor-common/safe-plugin');
require('./index-c202f0c5.cjs.dev.js');
require('prosemirror-tables');
require('@babel/runtime/helpers/createForOfIteratorHelper');
require('@uidu/analytics-listeners');
require('prosemirror-inputrules');
require('./ReactNodeView-b430da87.cjs.dev.js');
require('@babel/runtime/helpers/get');
require('@babel/runtime/helpers/getPrototypeOf');
require('w3c-keyname');
require('@atlaskit/icon/glyph/editor/text-style');
require('react-intl');
require('@loadable/component');
require('prop-types');
require('@uidu/date');
require('@uidu/menu');
require('@atlaskit/icon/glyph/editor/edit');
require('@atlaskit/icon/glyph/editor/media-center');
require('@atlaskit/icon/glyph/editor/media-full-width');
require('@atlaskit/icon/glyph/editor/media-wide');
require('@atlaskit/icon/glyph/editor/remove');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@atlaskit/icon/glyph/editor/file');
require('raf-schd');
require('@uidu/button');
require('@atlaskit/icon/glyph/editor/done');
require('@fortawesome/pro-regular-svg-icons');
require('@fortawesome/react-fontawesome');
require('@uidu/tooltip');
require('@atlaskit/icon/glyph/editor/layout-three-equal');
require('@atlaskit/icon/glyph/editor/layout-three-with-sidebars');
require('@atlaskit/icon/glyph/editor/layout-two-equal');
require('@atlaskit/icon/glyph/editor/layout-two-left-sidebar');
require('@atlaskit/icon/glyph/editor/layout-two-right-sidebar');
require('uuid');
require('@uidu/analytics-gas-types');
require('@atlaskit/icon/glyph/editor/mention');
require('@atlaskit/icon/glyph/chevron-right-circle');
require('@atlaskit/icon/glyph/editor/add');
require('@atlaskit/icon/glyph/editor/code');
require('@atlaskit/icon/glyph/editor/date');
require('@atlaskit/icon/glyph/editor/decision');
require('@atlaskit/icon/glyph/editor/horizontal-rule');
require('@atlaskit/icon/glyph/editor/info');
require('@atlaskit/icon/glyph/editor/more');
require('@atlaskit/icon/glyph/editor/task');
require('@atlaskit/icon/glyph/media-services/text');
require('@atlaskit/icon/glyph/status');
require('@emoji-mart/data');
require('@emoji-mart/react');
require('@atlaskit/icon/glyph/editor/bullet-list');
require('@atlaskit/icon/glyph/editor/number-list');
require('@atlaskit/icon/glyph/editor/close');
require('@uidu/media-filmstrip');
require('classnames');
require('@uidu/media-picker');
require('assert');
require('react-dom/client');
require('@atlaskit/icon/glyph/document-filled');
require('@uidu/media-card');
require('re-resizable');
require('@uidu/media-core');
require('@atlaskit/icon/glyph/chevron-left-large');
require('@atlaskit/icon/glyph/cross-circle');
require('@uidu/analytics');
require('@atlaskit/icon/glyph/media-services/annotate');
require('@atlaskit/icon/glyph/editor/align-image-center');
require('@atlaskit/icon/glyph/editor/align-image-left');
require('@atlaskit/icon/glyph/editor/align-image-right');
require('@atlaskit/icon/glyph/editor/media-wrap-left');
require('@atlaskit/icon/glyph/editor/media-wrap-right');
require('@atlaskit/icon/glyph/editor/link');
require('@atlaskit/icon/glyph/shortcut');
require('@atlaskit/icon/glyph/editor/unlink');
require('@uidu/spinner');
require('@atlaskit/icon/glyph/editor/attachment');
require('@uidu/field-base');
require('@uidu/status/element');
require('@uidu/status/picker');
require('@uidu/editor-common/ui-color');
require('@uidu/droplist');
require('@atlaskit/icon/glyph/editor/collapse');
require('@atlaskit/icon/glyph/editor/expand');
require('prosemirror-schema-list');
require('@uidu/editor-markdown-transformer');
require('linkify-it');
require('markdown-it');
require('@atlaskit/icon/glyph/editor/background-color');
require('@babel/runtime/helpers/toArray');
require('@atlaskit/icon/base');
require('get-video-id');

function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }

var FieldDate__default = /*#__PURE__*/_interopDefault(FieldDate);
var Form__default = /*#__PURE__*/_interopDefault(Form);
var ReactDOM__default = /*#__PURE__*/_interopDefault(ReactDOM);

var PopupWithListeners = main.withOuterListeners(editorCommon.Popup);
var calendarStyle = {
  padding: theme.borderRadius(),
  borderRadius: theme.borderRadius(),
  boxShadow: "0 4px 8px -2px ".concat(theme.colors.N60A, ", 0 0 1px ").concat(theme.colors.N60A),
  backgroundColor: theme.colors.N0
};
function DatePicker(props) {
  var element = props.element,
    closeDatePicker = props.closeDatePicker,
    onSelect = props.onSelect;
  var timestamp = element.getAttribute('timestamp');
  var _timestampToUTCDate = editorCommon.timestampToUTCDate(timestamp);
    _timestampToUTCDate.day;
    _timestampToUTCDate.month;
    _timestampToUTCDate.year;
  var _useState = React.useState({}),
    _useState2 = _slicedToArray(_useState, 2),
    state = _useState2[0],
    setState = _useState2[1];
  var handleChange = function handleChange(_ref) {
    var day = _ref.day,
      month = _ref.month,
      year = _ref.year;
    setState({
      day: day,
      month: month,
      year: year
    });
  };
  var handleRef = function handleRef(ref) {
    var elm = ref && ReactDOM__default["default"].findDOMNode(ref);
    if (elm) {
      elm.focus();
    }
  };
  var form = Form.useForm({});
  if (!timestamp) {
    return null;
  }
  return /*#__PURE__*/jsxRuntime.jsx(PopupWithListeners, {
    target: element,
    offset: [0, 8],
    fitHeight: 327,
    fitWidth: 340,
    handleClickOutside: closeDatePicker,
    handleEscapeKeydown: closeDatePicker,
    zIndex: editorCommon.akEditorFloatingDialogZIndex,
    children: /*#__PURE__*/jsxRuntime.jsx(Form__default["default"], {
      form: form,
      children: /*#__PURE__*/jsxRuntime.jsx(FieldDate__default["default"], _objectSpread(_objectSpread({
        withCalendar: true,
        name: "date",
        onChange: handleChange,
        onSelect: onSelect
      }, state), {}, {
        ref: handleRef,
        innerProps: {
          style: calendarStyle
        }
      }))
    })
  });
}

exports["default"] = DatePicker;
