import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
import React, { useRef } from "react";
import Popup from "../popup/index";
import CalendarItem from "../calendaritem/index";
import { Utils } from "../../utils/date";
import { useConfig } from "../configprovider/index";
import { ComponentDefaults } from "../../utils/typings";
var defaultProps = _object_spread_props(_object_spread({}, ComponentDefaults), {
    type: 'single',
    autoBackfill: false,
    popup: true,
    visible: false,
    title: '',
    defaultValue: '',
    startDate: Utils.getDay(0),
    endDate: Utils.getDay(365),
    showToday: true,
    startText: '',
    endText: '',
    confirmText: '',
    showTitle: true,
    showSubTitle: true,
    scrollAnimation: true,
    firstDayOfWeek: 0,
    disableDate: function(date) {
        return false;
    },
    renderHeaderButtons: undefined,
    renderDay: undefined,
    renderDayTop: undefined,
    renderDayBottom: undefined,
    onClose: function() {},
    onConfirm: function(param) {},
    onDayClick: function(data) {},
    onPageChange: function(param) {}
});
export var Calendar = /*#__PURE__*/ React.forwardRef(function(props, ref) {
    var locale = useConfig().locale;
    var _$_object_spread = _object_spread({}, defaultProps, props), style = _$_object_spread.style, className = _$_object_spread.className, children = _$_object_spread.children, popup = _$_object_spread.popup, visible = _$_object_spread.visible, type = _$_object_spread.type, autoBackfill = _$_object_spread.autoBackfill, title = _$_object_spread.title, defaultValue = _$_object_spread.defaultValue, startDate = _$_object_spread.startDate, endDate = _$_object_spread.endDate, showToday = _$_object_spread.showToday, startText = _$_object_spread.startText, endText = _$_object_spread.endText, confirmText = _$_object_spread.confirmText, showTitle = _$_object_spread.showTitle, showSubTitle = _$_object_spread.showSubTitle, scrollAnimation = _$_object_spread.scrollAnimation, firstDayOfWeek = _$_object_spread.firstDayOfWeek, closeIcon = _$_object_spread.closeIcon, disableDate = _$_object_spread.disableDate, renderHeaderButtons = _$_object_spread.renderHeaderButtons, renderBottomButton = _$_object_spread.renderBottomButton, renderDay = _$_object_spread.renderDay, renderDayTop = _$_object_spread.renderDayTop, renderDayBottom = _$_object_spread.renderDayBottom, onClose = _$_object_spread.onClose, onConfirm = _$_object_spread.onConfirm, onDayClick = _$_object_spread.onDayClick, onPageChange = _$_object_spread.onPageChange;
    var calendarRef = useRef(null);
    var close = function() {
        onClose && onClose();
    };
    var choose = function(param) {
        close();
        onConfirm && onConfirm(param);
    };
    var closePopup = function() {
        close();
    };
    var select = function(param) {
        onDayClick && onDayClick(param);
    };
    var scrollToDate = function(date) {
        var _calendarRef_current;
        (_calendarRef_current = calendarRef.current) === null || _calendarRef_current === void 0 ? void 0 : _calendarRef_current.scrollToDate(date);
    };
    var yearMonthChange = function(param) {
        onPageChange && onPageChange(param);
    };
    React.useImperativeHandle(ref, function() {
        return {
            scrollToDate: scrollToDate
        };
    });
    var renderItem = function() {
        return /*#__PURE__*/ React.createElement(CalendarItem, {
            ref: calendarRef,
            style: style,
            className: className,
            children: children,
            type: type,
            autoBackfill: autoBackfill,
            popup: popup,
            title: title || locale.calendaritem.title,
            defaultValue: defaultValue,
            startDate: startDate,
            endDate: endDate,
            showToday: showToday,
            startText: startText || locale.calendaritem.start,
            endText: endText || locale.calendaritem.end,
            confirmText: confirmText || locale.calendaritem.confirm,
            showTitle: showTitle,
            showSubTitle: showSubTitle,
            scrollAnimation: scrollAnimation,
            firstDayOfWeek: firstDayOfWeek,
            disableDate: disableDate,
            renderHeaderButtons: renderHeaderButtons,
            renderBottomButton: renderBottomButton,
            renderDay: renderDay,
            renderDayTop: renderDayTop,
            renderDayBottom: renderDayBottom,
            onConfirm: choose,
            onDayClick: select,
            onPageChange: yearMonthChange
        });
    };
    return /*#__PURE__*/ React.createElement(React.Fragment, null, popup ? /*#__PURE__*/ React.createElement(Popup, {
        className: "nut-calendar-popup",
        visible: visible,
        position: "bottom",
        round: true,
        closeable: true,
        destroyOnClose: true,
        onOverlayClick: closePopup,
        onCloseIconClick: closePopup,
        style: {
            height: '83%'
        },
        closeIcon: closeIcon
    }, renderItem()) : renderItem());
});
Calendar.displayName = 'NutCalendar';
