'use client';
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.Calendar = Calendar;
exports.CalendarDayButton = CalendarDayButton;
const jsx_runtime_1 = require("react/jsx-runtime");
const React = __importStar(require("react"));
const react_day_picker_1 = require("react-day-picker");
const utils_1 = require("../../../lib/utils");
const button_1 = require("../../../components/ui/button");
const lucide_react_1 = require("lucide-react");
function Calendar({ className, classNames, showOutsideDays = true, captionLayout = 'label', buttonVariant = 'plain', formatters, components, ...props }) {
    const defaultClassNames = (0, react_day_picker_1.getDefaultClassNames)();
    return ((0, jsx_runtime_1.jsx)(react_day_picker_1.DayPicker, { showOutsideDays: showOutsideDays, className: (0, utils_1.cn)('bg-background group/calendar p-2 [--cell-radius:var(--radius-md)] [--cell-size:34px] [--nav-size:28px] [[data-slot=card-content]_&]:bg-transparent [[data-slot=popover-content]_&]:bg-transparent', String.raw `rtl:**:[.rdp-button\_next>svg]:rotate-180`, String.raw `rtl:**:[.rdp-button\_previous>svg]:rotate-180`, className), captionLayout: captionLayout, formatters: {
            formatMonthDropdown: (date) => date.toLocaleString('default', { month: 'short' }),
            ...formatters
        }, classNames: {
            root: (0, utils_1.cn)('w-fit', defaultClassNames.root),
            months: (0, utils_1.cn)('flex gap-4 flex-col md:flex-row relative', defaultClassNames.months),
            month: (0, utils_1.cn)('flex flex-col w-full gap-4', defaultClassNames.month),
            nav: (0, utils_1.cn)('flex items-center gap-1 w-full absolute top-0 inset-x-0 justify-between', defaultClassNames.nav),
            button_previous: (0, utils_1.cn)((0, button_1.buttonVariants)({ variant: buttonVariant }), 'size-(--nav-size) aria-disabled:opacity-50 p-0 select-none', defaultClassNames.button_previous),
            button_next: (0, utils_1.cn)((0, button_1.buttonVariants)({ variant: buttonVariant }), 'size-(--nav-size) aria-disabled:opacity-50 p-0 select-none', defaultClassNames.button_next),
            month_caption: (0, utils_1.cn)('flex items-center justify-center h-(--nav-size) w-full px-(--nav-size)', defaultClassNames.month_caption),
            dropdowns: (0, utils_1.cn)('w-full flex items-center text-sm font-medium justify-center h-(--cell-size) gap-1.5', defaultClassNames.dropdowns),
            dropdown_root: (0, utils_1.cn)('relative cn-calendar-dropdown-root rounded-(--cell-radius)', defaultClassNames.dropdown_root),
            dropdown: (0, utils_1.cn)('absolute bg-popover inset-0 opacity-0', defaultClassNames.dropdown),
            caption_label: (0, utils_1.cn)('select-none font-bold', captionLayout === 'label'
                ? 'text-sm'
                : 'cn-calendar-caption-label rounded-(--cell-radius) flex items-center gap-1 text-sm  [&>svg]:text-muted-foreground [&>svg]:size-3.5', defaultClassNames.caption_label),
            table: 'w-full border-collapse',
            weekdays: (0, utils_1.cn)('flex gap-0.5', defaultClassNames.weekdays),
            weekday: (0, utils_1.cn)('text-muted-foreground rounded-(--cell-radius) flex-1 font-normal text-[0.8rem] select-none', defaultClassNames.weekday),
            week: (0, utils_1.cn)('flex w-full gap-0.5', defaultClassNames.week),
            week_number_header: (0, utils_1.cn)('select-none w-(--cell-size)', defaultClassNames.week_number_header),
            week_number: (0, utils_1.cn)('text-[0.8rem] select-none text-muted-foreground', defaultClassNames.week_number),
            day: (0, utils_1.cn)('relative w-full rounded-(--cell-radius) h-full p-0 text-center [&:last-child[data-selected=true]_button]:rounded-r-(--cell-radius) group/day aspect-square select-none', props.showWeekNumber
                ? '[&:nth-child(2)[data-selected=true]_button]:rounded-l-(--cell-radius)'
                : '[&:first-child[data-selected=true]_button]:rounded-l-(--cell-radius)', defaultClassNames.day),
            range_start: (0, utils_1.cn)('rounded-l-(--cell-radius) bg-accent-mute relative after:bg-accent-mute after:absolute after:inset-y-0 after:w-4 after:right-0 -z-0 isolate', defaultClassNames.range_start),
            range_middle: (0, utils_1.cn)('rounded-none', defaultClassNames.range_middle),
            range_end: (0, utils_1.cn)('rounded-r-(--cell-radius) bg-accent-mute relative after:bg-accent-mute after:absolute after:inset-y-0 after:w-4 after:left-0 -z-0 isolate', defaultClassNames.range_end),
            today: (0, utils_1.cn)('text-foreground rounded-(--cell-radius)', defaultClassNames.today),
            outside: (0, utils_1.cn)('text-muted-foreground opacity-60 aria-selected:text-muted-foreground', defaultClassNames.outside),
            disabled: (0, utils_1.cn)('text-muted-foreground opacity-50', defaultClassNames.disabled),
            hidden: (0, utils_1.cn)('invisible', defaultClassNames.hidden),
            ...classNames
        }, components: {
            Root: ({ className, rootRef, ...props }) => {
                return ((0, jsx_runtime_1.jsx)("div", { "data-slot": "calendar", ref: rootRef, className: (0, utils_1.cn)(className), ...props }));
            },
            Chevron: ({ className, orientation, ...props }) => {
                if (orientation === 'left') {
                    return ((0, jsx_runtime_1.jsx)(lucide_react_1.ChevronLeftIcon, { className: (0, utils_1.cn)('size-4', className), ...props }));
                }
                if (orientation === 'right') {
                    return ((0, jsx_runtime_1.jsx)(lucide_react_1.ChevronRightIcon, { className: (0, utils_1.cn)('size-4', className), ...props }));
                }
                return ((0, jsx_runtime_1.jsx)(lucide_react_1.ChevronDownIcon, { className: (0, utils_1.cn)('size-4', className), ...props }));
            },
            DayButton: CalendarDayButton,
            WeekNumber: ({ children, ...props }) => {
                return ((0, jsx_runtime_1.jsx)("td", { ...props, children: (0, jsx_runtime_1.jsx)("div", { className: "flex size-(--cell-size) items-center justify-center text-center", children: children }) }));
            },
            ...components
        }, ...props }));
}
function CalendarDayButton({ className, day, modifiers, ...props }) {
    const defaultClassNames = (0, react_day_picker_1.getDefaultClassNames)();
    const ref = React.useRef(null);
    React.useEffect(() => {
        if (modifiers.focused)
            ref.current?.focus();
    }, [modifiers.focused]);
    const dayNumber = day.date.getDate();
    const monthName = day.date.toLocaleDateString('en', { month: 'long' });
    const year = day.date.getFullYear();
    return ((0, jsx_runtime_1.jsx)(button_1.Button, { ref: ref, variant: "plain", size: "small", "data-day": day.date.toLocaleDateString(), "data-selected-single": modifiers.selected &&
            !modifiers.range_start &&
            !modifiers.range_end &&
            !modifiers.range_middle, "data-range-start": modifiers.range_start, "data-range-end": modifiers.range_end, "data-range-middle": modifiers.range_middle, "data-today": modifiers.today && !modifiers.range_middle, "aria-label": `${monthName} ${dayNumber}, ${year}`, "aria-selected": modifiers.selected, "aria-current": modifiers.today ? 'date' : undefined, "aria-disabled": modifiers.disabled, role: "gridcell", tabIndex: modifiers.focused ? 0 : -1, className: (0, utils_1.cn)('data-[today=true]:bg-accent data-[today=true]:text-accent-foreground data-[selected-single=true]:bg-accent data-[selected-single=true]:text-accent-foreground data-[range-middle=true]:bg-accent-mute data-[range-middle=true]:text-foreground data-[range-start=true]:bg-accent data-[range-start=true]:text-accent-foreground data-[range-end=true]:bg-accent data-[range-end=true]:text-accent-foreground focus-visible:border-accent focus-visible:ring-accent/50 relative isolate z-10 flex aspect-square size-auto w-full min-w-(--cell-size) flex-col gap-1 border-0 leading-none font-normal focus-visible:ring-[3px] focus-visible:outline-none data-[range-end=true]:rounded-(--cell-radius) data-[range-end=true]:rounded-r-(--cell-radius) data-[range-end=true]:font-bold data-[range-middle=true]:rounded-none data-[range-start=true]:rounded-(--cell-radius) data-[range-start=true]:rounded-l-(--cell-radius) data-[range-start=true]:font-bold data-[selected-single=true]:font-bold data-[today=true]:font-bold [&>span]:text-xs [&>span]:opacity-70', defaultClassNames.day, className), ...props }));
}
