"use strict";
// The require scope
var __webpack_require__ = {};
/************************************************************************/ // webpack/runtime/compat_get_default_export
(()=>{
    // getDefaultExport function for compatibility with non-ESM modules
    __webpack_require__.n = function(module) {
        var getter = module && module.__esModule ? function() {
            return module['default'];
        } : function() {
            return module;
        };
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
// webpack/runtime/define_property_getters
(()=>{
    __webpack_require__.d = function(exports1, definition) {
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
// webpack/runtime/has_own_property
(()=>{
    __webpack_require__.o = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
// webpack/runtime/make_namespace_object
(()=>{
    // define __esModule on exports
    __webpack_require__.r = function(exports1) {
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
/************************************************************************/ var __webpack_exports__ = {};
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// EXPORTS
__webpack_require__.d(__webpack_exports__, {
    default: ()=>/* binding */ DateTimePicker_rslib_entry_
});
const external_react_namespaceObject = require("react");
const react_namespaceObject = require("@chakra-ui/react");
const en_US_namespaceObject = require("date-fns/locale/en-US");
var en_US_default = /*#__PURE__*/ __webpack_require__.n(en_US_namespaceObject);
const zonedTimeToUtc_namespaceObject = require("date-fns-tz/zonedTimeToUtc");
var zonedTimeToUtc_default = /*#__PURE__*/ __webpack_require__.n(zonedTimeToUtc_namespaceObject);
const external_react_datepicker_namespaceObject = require("react-datepicker");
var external_react_datepicker_default = /*#__PURE__*/ __webpack_require__.n(external_react_datepicker_namespaceObject);
const DEFAULT_TIMEZONE = 'Europe/Berlin';
const TIMEZONE_OPTIONS = [
    'Local',
    'UTC'
];
const DateTimePicker = ({ onChange, showTimezoneOptions = true, showButtons = true, showTimeSelect = true, showWeekNumbers = false, defaultDate, defaultTimezone = 'Local', ...props })=>{
    const [startDate, setStartDate] = (0, external_react_namespaceObject.useState)(defaultDate);
    const [timezone, setTimezone] = (0, external_react_namespaceObject.useState)(defaultTimezone);
    const handleDateTimeChange = (date, event)=>{
        if (date) {
            const utcDateAsLocal = 'UTC' === timezone ? zonedTimeToUtc_default()(date, DEFAULT_TIMEZONE, {
                locale: en_US_default()
            }) : date;
            const dateString = utcDateAsLocal.toUTCString();
            const formattedStartDate = 'UTC' === timezone ? new Date(utcDateAsLocal) : date;
            setStartDate(formattedStartDate);
            onChange(date, dateString, timezone);
        }
    };
    return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(external_react_datepicker_default(), {
        ...props,
        showTimeSelect: true // Always show both date and time picker
        ,
        selected: startDate,
        onChange: handleDateTimeChange,
        locale: en_US_default(),
        timeCaption: props.timeCaption ?? `Time - ${timezone}`,
        fixedHeight: true // Avoid layout shift
    }, /*#__PURE__*/ React.createElement(react_namespaceObject.Flex, {
        pl: 2,
        pb: 2,
        width: "100%"
    }, /*#__PURE__*/ React.createElement(react_namespaceObject.VStack, {
        align: "stretch",
        width: "100%"
    }, showButtons && /*#__PURE__*/ React.createElement(react_namespaceObject.ButtonGroup, {
        display: "flex",
        px: 4,
        py: 1
    }, /*#__PURE__*/ React.createElement(react_namespaceObject.Button, {
        size: "xs",
        variant: "link",
        textDecoration: "unset",
        onClick: ()=>setStartDate(new Date(Date.now()))
    }, "Today"), /*#__PURE__*/ React.createElement(react_namespaceObject.Spacer, null), /*#__PURE__*/ React.createElement(react_namespaceObject.Button, {
        size: "xs",
        variant: "link",
        textDecoration: "unset",
        onClick: ()=>setStartDate(void 0)
    }, "Clear")), showTimezoneOptions && /*#__PURE__*/ React.createElement(react_namespaceObject.RadioGroup, {
        value: timezone,
        onChange: (nextTimezone)=>{
            setTimezone(nextTimezone);
            setStartDate('UTC' === nextTimezone && startDate ? zonedTimeToUtc_default()(startDate, DEFAULT_TIMEZONE) : startDate);
        }
    }, /*#__PURE__*/ React.createElement(react_namespaceObject.Stack, {
        spacing: 4,
        direction: "row"
    }, TIMEZONE_OPTIONS.map((timezone)=>/*#__PURE__*/ React.createElement(react_namespaceObject.Radio, {
            value: timezone,
            colorScheme: "brand"
        }, timezone))))))));
};
/* ESM default export */ const DateTimePicker_rslib_entry_ = DateTimePicker;
var __webpack_export_target__ = exports;
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
    value: true
});
