"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "Calendar", {
    enumerable: true,
    get: function() {
        return Calendar;
    }
});
var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
var _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
var _object_spread = require("@swc/helpers/_/_object_spread");
var _object_spread_props = require("@swc/helpers/_/_object_spread_props");
var _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
var _index = /*#__PURE__*/ _interop_require_default._(require("../popup/index"));
var _index1 = /*#__PURE__*/ _interop_require_default._(require("../calendaritem/index"));
var _date = require("../../utils/date");
var _index2 = require("../configprovider/index");
var _typings = require("../../utils/typings");
var defaultProps = (0, _object_spread_props._)((0, _object_spread._)({}, _typings.ComponentDefaults), {
    type: 'single',
    autoBackfill: false,
    popup: true,
    visible: false,
    title: '',
    defaultValue: '',
    startDate: _date.Utils.getDay(0),
    endDate: _date.Utils.getDay(365),
    showToday: true,
    startText: '',
    endText: '',
    confirmText: '',
    showTitle: true,
    showSubTitle: true,
    scrollAnimation: true,
    firstDayOfWeek: 0,
    disableDate: function disableDate(date) {
        return false;
    },
    renderHeaderButtons: undefined,
    renderDay: undefined,
    renderDayTop: undefined,
    renderDayBottom: undefined,
    onClose: function onClose() {},
    onConfirm: function onConfirm(param) {},
    onDayClick: function onDayClick(data) {},
    onPageChange: function onPageChange(param) {}
});
var Calendar = /*#__PURE__*/ _react.default.forwardRef(function(props, ref) {
    var locale = (0, _index2.useConfig)().locale;
    var _$_object_spread = (0, _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 = (0, _react.useRef)(null);
    var close = function close() {
        onClose && onClose();
    };
    var choose = function choose(param) {
        close();
        onConfirm && onConfirm(param);
    };
    var closePopup = function closePopup() {
        close();
    };
    var select = function select(param) {
        onDayClick && onDayClick(param);
    };
    var scrollToDate = function scrollToDate(date) {
        var _calendarRef_current;
        (_calendarRef_current = calendarRef.current) === null || _calendarRef_current === void 0 ? void 0 : _calendarRef_current.scrollToDate(date);
    };
    var yearMonthChange = function yearMonthChange(param) {
        onPageChange && onPageChange(param);
    };
    _react.default.useImperativeHandle(ref, function() {
        return {
            scrollToDate: scrollToDate
        };
    });
    var renderItem = function renderItem() {
        return /*#__PURE__*/ _react.default.createElement(_index1.default, {
            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.default.createElement(_react.default.Fragment, null, popup ? /*#__PURE__*/ _react.default.createElement(_index.default, {
        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';
