import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE__chakra_ui_react__ from "@chakra-ui/react";
import * as __WEBPACK_EXTERNAL_MODULE_date_fns_locale_en_US__ from "date-fns/locale/en-US";
import * as __WEBPACK_EXTERNAL_MODULE_date_fns_tz_zonedTimeToUtc__ from "date-fns-tz/zonedTimeToUtc";
import * as __WEBPACK_EXTERNAL_MODULE_react_datepicker__ from "react-datepicker";
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, __WEBPACK_EXTERNAL_MODULE_react__.useState)(defaultDate);
    const [timezone, setTimezone] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(defaultTimezone);
    const handleDateTimeChange = (date, event)=>{
        if (date) {
            const utcDateAsLocal = 'UTC' === timezone ? (0, __WEBPACK_EXTERNAL_MODULE_date_fns_tz_zonedTimeToUtc__["default"])(date, DEFAULT_TIMEZONE, {
                locale: __WEBPACK_EXTERNAL_MODULE_date_fns_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(__WEBPACK_EXTERNAL_MODULE_react_datepicker__["default"], {
        ...props,
        showTimeSelect: true // Always show both date and time picker
        ,
        selected: startDate,
        onChange: handleDateTimeChange,
        locale: __WEBPACK_EXTERNAL_MODULE_date_fns_locale_en_US__["default"],
        timeCaption: props.timeCaption ?? `Time - ${timezone}`,
        fixedHeight: true // Avoid layout shift
    }, /*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__chakra_ui_react__.Flex, {
        pl: 2,
        pb: 2,
        width: "100%"
    }, /*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__chakra_ui_react__.VStack, {
        align: "stretch",
        width: "100%"
    }, showButtons && /*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__chakra_ui_react__.ButtonGroup, {
        display: "flex",
        px: 4,
        py: 1
    }, /*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__chakra_ui_react__.Button, {
        size: "xs",
        variant: "link",
        textDecoration: "unset",
        onClick: ()=>setStartDate(new Date(Date.now()))
    }, "Today"), /*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__chakra_ui_react__.Spacer, null), /*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__chakra_ui_react__.Button, {
        size: "xs",
        variant: "link",
        textDecoration: "unset",
        onClick: ()=>setStartDate(void 0)
    }, "Clear")), showTimezoneOptions && /*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__chakra_ui_react__.RadioGroup, {
        value: timezone,
        onChange: (nextTimezone)=>{
            setTimezone(nextTimezone);
            setStartDate('UTC' === nextTimezone && startDate ? (0, __WEBPACK_EXTERNAL_MODULE_date_fns_tz_zonedTimeToUtc__["default"])(startDate, DEFAULT_TIMEZONE) : startDate);
        }
    }, /*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__chakra_ui_react__.Stack, {
        spacing: 4,
        direction: "row"
    }, TIMEZONE_OPTIONS.map((timezone)=>/*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__chakra_ui_react__.Radio, {
            value: timezone,
            colorScheme: "brand"
        }, timezone))))))));
};
/* ESM default export */ const DateTimePicker_rslib_entry_ = DateTimePicker;
export { DateTimePicker_rslib_entry_ as default };
