"use client";
import { jsx, jsxs } from 'react/jsx-runtime';
import { ChevronLeftIcon, ChevronRightIcon, ChevronUpIcon, ChevronDownIcon } from '../../node_modules/.pnpm/@radix-ui_react-icons@1.3.2_react@19.1.1/node_modules/@radix-ui/react-icons/dist/react-icons.esm.js';
import { cx, cva } from '../../node_modules/.pnpm/class-variance-authority@0.7.1/node_modules/class-variance-authority/dist/index.js';
import { useState, useEffect } from 'react';
import { Flex } from '../flex/flex.js';
import { IconButton } from '../icon-button/icon-button.js';
import { Select } from '../select/select.js';
import { Skeleton } from '../skeleton/skeleton.js';
import { Tooltip } from '../tooltip/tooltip.js';
import styles from './calendar.module.css.js';
import { DayPicker } from '../../node_modules/.pnpm/react-day-picker@9.6.7_react@19.1.1/node_modules/react-day-picker/dist/esm/DayPicker.js';
import { dateLib } from '../../node_modules/.pnpm/react-day-picker@9.6.7_react@19.1.1/node_modules/react-day-picker/dist/esm/classes/DateLib.js';

const root = cva(styles.calendarRoot);
function DropDown({ options = [], value, onChange, onDropdownOpen, disabled }) {
    const [open, setOpen] = useState(false);
    useEffect(() => {
        if (open && onDropdownOpen)
            onDropdownOpen();
    }, [open, onDropdownOpen]);
    function handleChange(value) {
        if (onChange) {
            onChange({ target: { value } });
        }
    }
    return (jsxs(Select, { value: value?.toString(), onValueChange: handleChange, open: open, onOpenChange: setOpen, children: [jsx(Select.Trigger, { className: styles.dropdown_trigger, iconProps: {
                    className: styles.dropdown_icon
                }, size: 'small', variant: 'text', disabled: disabled, children: jsx(Select.Value, {}) }), jsxs(Select.Content, { className: styles.dropdown_content, children: [jsx(Select.ScrollUpButton, { asChild: true, children: jsx(Flex, { justify: 'center', children: jsx(ChevronUpIcon, {}) }) }), jsx(Select.Viewport, { children: options.map(opt => (jsx(Select.Item, { value: opt.value.toString(), disabled: opt.disabled, children: opt.label }, opt.value))) }), jsx(Select.ScrollDownButton, { asChild: true, children: jsx(Flex, { justify: 'center', children: jsx(ChevronDownIcon, {}) }) })] })] }));
}
const Calendar = function ({ className, classNames, showOutsideDays = true, onDropdownOpen, showTooltip = false, tooltipMessages = {}, loadingData = false, timeZone, ...props }) {
    return (jsx(DayPicker, { showOutsideDays: showOutsideDays, timeZone: timeZone, components: {
            Chevron: props => {
                const icon = props.orientation === 'left' ? (jsx(ChevronLeftIcon, {})) : (jsx(ChevronRightIcon, {}));
                return (jsx(IconButton, { ...props, disabled: loadingData, className: cx(props.className, loadingData && styles.disabled), size: 3, "aria-label": props.orientation === 'left' ? 'Previous month' : 'Next month', children: icon }));
            },
            Dropdown: (props) => (jsx(DropDown, { ...props, onDropdownOpen: onDropdownOpen, disabled: loadingData })),
            DayButton: props => {
                const { day, ...buttonProps } = props;
                const message = tooltipMessages[dateLib.format(day.date, 'dd-MM-yyyy')];
                return (jsx(Tooltip, { side: 'top', disabled: loadingData || !showTooltip || !message, message: message, children: jsx("button", { ...buttonProps }) }));
            },
            MonthGrid: props => loadingData ? (jsx(Skeleton, { count: 5, height: '18px', width: '252px', style: { marginBottom: 'var(--rs-space-6)' } })) : (jsx("table", { ...props }))
        }, classNames: {
            caption_label: styles.caption_label,
            button_previous: `${styles.nav_button} ${styles.nav_button_previous}`,
            button_next: `${styles.nav_button} ${styles.nav_button_next}`,
            month_caption: styles.month_caption,
            months: styles.months,
            nav: styles.nav,
            day: styles.day,
            today: styles.today,
            outside: styles.outside,
            week: styles.week,
            weekdays: styles.week,
            weekday: styles.weekday,
            disabled: styles.disabled,
            selected: styles.selected,
            day_button: styles.day_button,
            range_middle: styles.range_middle,
            range_end: styles.range_end,
            range_start: styles.range_start,
            hidden: styles.hidden,
            dropdowns: styles.dropdowns,
            ...classNames
        }, className: root({ className }), mode: 'single', ...props }));
};

export { Calendar };
//# sourceMappingURL=calendar.js.map
