'use strict';

var jsxRuntime = require('../node_modules/.pnpm/react@18.2.0/node_modules/react/jsx-runtime.cjs');
var DayPicker = require('../node_modules/.pnpm/react-day-picker@9.0.4_react@18.2.0/node_modules/react-day-picker/dist/esm/DayPicker.cjs');
var React = require('react');
require('../node_modules/.pnpm/react-day-picker@9.0.4_react@18.2.0/node_modules/react-day-picker/dist/esm/useDayPicker.cjs');
var dateLib = require('../node_modules/.pnpm/react-day-picker@9.0.4_react@18.2.0/node_modules/react-day-picker/dist/esm/lib/dateLib.cjs');
require('../node_modules/.pnpm/react-day-picker@9.0.4_react@18.2.0/node_modules/react-day-picker/dist/esm/UI.cjs');
var index$1 = require('../node_modules/.pnpm/class-variance-authority@0.6.0_typescript@5.4.3/node_modules/class-variance-authority/dist/index.cjs');
var reactIcons_esm = require('../node_modules/.pnpm/@radix-ui_react-icons@1.3.0_react@18.2.0/node_modules/@radix-ui/react-icons/dist/react-icons.esm.cjs');
var calendar_module = require('./calendar.module.css.cjs');
var select = require('../select/select.cjs');
var flex = require('../flex/flex.cjs');
var tooltip = require('../tooltip/tooltip.cjs');
var index = require('../node_modules/.pnpm/react-loading-skeleton@3.4.0_react@18.2.0/node_modules/react-loading-skeleton/dist/index.cjs');

const root = index$1.cva(calendar_module.default.calendarRoot);
function DropDown({ options = [], value, onChange, onDropdownOpen, }) {
    const [open, setOpen] = React.useState(false);
    React.useEffect(() => {
        if (open && onDropdownOpen)
            onDropdownOpen();
    }, [open]);
    function handleChange(value) {
        if (onChange) {
            onChange({ target: { value } });
        }
    }
    return (jsxRuntime.jsxRuntimeExports.jsxs(select.Select, { value: value?.toString(), onValueChange: handleChange, open: open, onOpenChange: setOpen, children: [jsxRuntime.jsxRuntimeExports.jsx(select.Select.Trigger, { className: calendar_module.default.dropdown_trigger, iconProps: {
                    className: calendar_module.default.dropdown_icon,
                }, children: jsxRuntime.jsxRuntimeExports.jsx(select.Select.Value, {}) }), jsxRuntime.jsxRuntimeExports.jsxs(select.Select.Content, { className: calendar_module.default.dropdown_content, children: [jsxRuntime.jsxRuntimeExports.jsx(select.Select.ScrollUpButton, { asChild: true, children: jsxRuntime.jsxRuntimeExports.jsx(flex.Flex, { justify: 'center', children: jsxRuntime.jsxRuntimeExports.jsx(reactIcons_esm.ChevronUpIcon, {}) }) }), jsxRuntime.jsxRuntimeExports.jsx(select.Select.Viewport, { children: options.map((opt) => (jsxRuntime.jsxRuntimeExports.jsx(select.Select.Item, { value: opt.value.toString(), disabled: opt.disabled, textProps: {
                                className: calendar_module.default.dropdown_item_text,
                            }, children: opt.label }, opt.value))) }), jsxRuntime.jsxRuntimeExports.jsx(select.Select.ScrollDownButton, { asChild: true, children: jsxRuntime.jsxRuntimeExports.jsx(flex.Flex, { justify: 'center', children: jsxRuntime.jsxRuntimeExports.jsx(reactIcons_esm.ChevronDownIcon, {}) }) })] })] }));
}
const Calendar = function ({ className, classNames, showOutsideDays = true, onDropdownOpen, showTooltip = false, tooltipMessages = {}, loadingData = false, ...props }) {
    return (jsxRuntime.jsxRuntimeExports.jsx(DayPicker.DayPicker, { showOutsideDays: showOutsideDays, components: {
            Chevron: (props) => {
                if (props.orientation === 'left') {
                    return jsxRuntime.jsxRuntimeExports.jsx(reactIcons_esm.ChevronLeftIcon, { ...props });
                }
                return jsxRuntime.jsxRuntimeExports.jsx(reactIcons_esm.ChevronRightIcon, { ...props });
            },
            Dropdown: (props) => (jsxRuntime.jsxRuntimeExports.jsx(DropDown, { ...props, onDropdownOpen: onDropdownOpen })),
            DayButton: (props) => {
                const { day, ...buttonProps } = props;
                const message = tooltipMessages[dateLib.dateLib.format(day.date, 'dd-MM-yyyy')];
                return (jsxRuntime.jsxRuntimeExports.jsx(tooltip.Tooltip, { side: "top", disabled: loadingData || !showTooltip || !message, message: message, children: jsxRuntime.jsxRuntimeExports.jsx("button", { ...buttonProps }) }));
            },
            MonthGrid: (props) => loadingData ? (jsxRuntime.jsxRuntimeExports.jsx(index.default, { count: 6, height: '12px', width: '252px', style: { marginBottom: 'var(--space-5)' }, highlightColor: "var(--background-base)", baseColor: "var(--background-base-hover)" })) : (jsxRuntime.jsxRuntimeExports.jsx("table", { ...props })),
        }, classNames: {
            caption_label: calendar_module.default.caption_label,
            button_previous: `${calendar_module.default.nav_button} ${calendar_module.default.nav_button_previous}`,
            button_next: `${calendar_module.default.nav_button} ${calendar_module.default.nav_button_next}`,
            month_caption: calendar_module.default.month_caption,
            months: calendar_module.default.months,
            nav: calendar_module.default.nav,
            day: calendar_module.default.day,
            today: calendar_module.default.today,
            outside: calendar_module.default.outside,
            week: calendar_module.default.week,
            weekdays: calendar_module.default.week,
            weekday: calendar_module.default.weekday,
            disabled: calendar_module.default.disabled,
            selected: calendar_module.default.selected,
            day_button: calendar_module.default.day_button,
            range_middle: calendar_module.default.range_middle,
            range_end: calendar_module.default.range_end,
            range_start: calendar_module.default.range_start,
            hidden: calendar_module.default.hidden,
            dropdowns: calendar_module.default.dropdowns,
            ...classNames,
        }, className: root({ className }), mode: "single", ...props }));
};

exports.Calendar = Calendar;
//# sourceMappingURL=calendar.cjs.map
