"use client";
'use strict';

var jsxRuntime = require('react/jsx-runtime');
var reactIcons_esm = require('../../node_modules/.pnpm/@radix-ui_react-icons@1.3.2_react@19.1.1/node_modules/@radix-ui/react-icons/dist/react-icons.esm.cjs');
var index = require('../../node_modules/.pnpm/class-variance-authority@0.7.1/node_modules/class-variance-authority/dist/index.cjs');
var React = require('react');
var flex = require('../flex/flex.cjs');
var iconButton = require('../icon-button/icon-button.cjs');
var select = require('../select/select.cjs');
var skeleton = require('../skeleton/skeleton.cjs');
var tooltip = require('../tooltip/tooltip.cjs');
var calendar_module = require('./calendar.module.css.cjs');
var DayPicker = require('../../node_modules/.pnpm/react-day-picker@9.6.7_react@19.1.1/node_modules/react-day-picker/dist/esm/DayPicker.cjs');
var DateLib = require('../../node_modules/.pnpm/react-day-picker@9.6.7_react@19.1.1/node_modules/react-day-picker/dist/esm/classes/DateLib.cjs');

const root = index.cva(calendar_module.default.calendarRoot);
function DropDown({ options = [], value, onChange, onDropdownOpen, disabled }) {
    const [open, setOpen] = React.useState(false);
    React.useEffect(() => {
        if (open && onDropdownOpen)
            onDropdownOpen();
    }, [open, onDropdownOpen]);
    function handleChange(value) {
        if (onChange) {
            onChange({ target: { value } });
        }
    }
    return (jsxRuntime.jsxs(select.Select, { value: value?.toString(), onValueChange: handleChange, open: open, onOpenChange: setOpen, children: [jsxRuntime.jsx(select.Select.Trigger, { className: calendar_module.default.dropdown_trigger, iconProps: {
                    className: calendar_module.default.dropdown_icon
                }, size: 'small', variant: 'text', disabled: disabled, children: jsxRuntime.jsx(select.Select.Value, {}) }), jsxRuntime.jsxs(select.Select.Content, { className: calendar_module.default.dropdown_content, children: [jsxRuntime.jsx(select.Select.ScrollUpButton, { asChild: true, children: jsxRuntime.jsx(flex.Flex, { justify: 'center', children: jsxRuntime.jsx(reactIcons_esm.ChevronUpIcon, {}) }) }), jsxRuntime.jsx(select.Select.Viewport, { children: options.map(opt => (jsxRuntime.jsx(select.Select.Item, { value: opt.value.toString(), disabled: opt.disabled, children: opt.label }, opt.value))) }), jsxRuntime.jsx(select.Select.ScrollDownButton, { asChild: true, children: jsxRuntime.jsx(flex.Flex, { justify: 'center', children: jsxRuntime.jsx(reactIcons_esm.ChevronDownIcon, {}) }) })] })] }));
}
const Calendar = function ({ className, classNames, showOutsideDays = true, onDropdownOpen, showTooltip = false, tooltipMessages = {}, loadingData = false, timeZone, ...props }) {
    return (jsxRuntime.jsx(DayPicker.DayPicker, { showOutsideDays: showOutsideDays, timeZone: timeZone, components: {
            Chevron: props => {
                const icon = props.orientation === 'left' ? (jsxRuntime.jsx(reactIcons_esm.ChevronLeftIcon, {})) : (jsxRuntime.jsx(reactIcons_esm.ChevronRightIcon, {}));
                return (jsxRuntime.jsx(iconButton.IconButton, { ...props, disabled: loadingData, className: index.cx(props.className, loadingData && calendar_module.default.disabled), size: 3, "aria-label": props.orientation === 'left' ? 'Previous month' : 'Next month', children: icon }));
            },
            Dropdown: (props) => (jsxRuntime.jsx(DropDown, { ...props, onDropdownOpen: onDropdownOpen, disabled: loadingData })),
            DayButton: props => {
                const { day, ...buttonProps } = props;
                const message = tooltipMessages[DateLib.dateLib.format(day.date, 'dd-MM-yyyy')];
                return (jsxRuntime.jsx(tooltip.Tooltip, { side: 'top', disabled: loadingData || !showTooltip || !message, message: message, children: jsxRuntime.jsx("button", { ...buttonProps }) }));
            },
            MonthGrid: props => loadingData ? (jsxRuntime.jsx(skeleton.Skeleton, { count: 5, height: '18px', width: '252px', style: { marginBottom: 'var(--rs-space-6)' } })) : (jsxRuntime.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
