/**
 * @license MIT
 * author: Cube Dev Team
 * @cube-dev/ui-kit v0.0.0-canary-c015414
 * Released under the MIT license.
 */

import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { createCalendar } from '@internationalized/date';
import { createDOMRef } from '@react-spectrum/utils';
import { forwardRef, useImperativeHandle, useRef } from 'react';
import { useCalendar, useLocale, } from 'react-aria';
import { useCalendarState } from 'react-stately';
import { LeftIcon, RightIcon } from '../../../icons/index.js';
import { useProviderProps } from '../../../provider.js';
import { tasty } from '../../../tasty/index.js';
import { Button } from '../../actions/index.js';
import { Title } from '../../content/Title.js';
import { Space } from '../../layout/Space.js';
import { CalendarGrid } from './CalendarGrid.js';
const CalendarElement = tasty({
    styles: {
        padding: '1x',
        gap: '1x',
    },
});
const CalendarHeaderElement = tasty({
    styles: {
        display: 'flex',
        placeContent: 'center space-between',
        placeItems: 'center',
        gap: '1.5x',
    },
});
function Calendar(props, ref) {
    props = useProviderProps(props);
    let { locale } = useLocale();
    let state = useCalendarState({
        ...props,
        locale,
        createCalendar,
    });
    let domRef = useRef(null);
    useImperativeHandle(ref, () => ({
        ...createDOMRef(domRef),
        focus() {
            state.setFocused(true);
        },
    }));
    let { calendarProps, prevButtonProps, nextButtonProps, title } = useCalendar(props, state);
    return (_jsxs(CalendarElement, { ...calendarProps, children: [_jsxs(CalendarHeaderElement, { children: [_jsx(Title, { level: 6, preset: "h6", children: title }), _jsxs(Space, { gap: ".5x", children: [_jsx(Button, { size: "xsmall", ...prevButtonProps, icon: _jsx(LeftIcon, {}) }), _jsx(Button, { size: "xsmall", ...nextButtonProps, icon: _jsx(RightIcon, {}) })] })] }), _jsx(CalendarGrid, { state: state, selectedRange: props.selectedRange })] }));
}
const _Calendar = forwardRef(Calendar);
_Calendar.displayName = 'Calendar';
export { _Calendar as Calendar };

        