import { _ as _define_property } from "@swc/helpers/_/_define_property";
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties";
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
import React from "react";
import classNames from "classnames";
import { View, Text } from "@tarojs/components";
import { useConfig } from "../configprovider/index";
import { usePropsValue } from "../../hooks/use-props-value";
import { ComponentDefaults } from "../../utils/typings";
import { addColorForHarmony } from "../../utils/taro/add-color-for-harmony";
import { usePagination } from "../../hooks/use-pagination";
var defaultProps = _object_spread_props(_object_spread({}, ComponentDefaults), {
    defaultValue: 1,
    mode: 'multi',
    prev: null,
    next: null,
    total: 50,
    pageSize: 10,
    itemSize: 5,
    ellipse: false
});
export var Pagination = function(props) {
    var locale = useConfig().locale;
    var _ref = _object_spread({}, defaultProps, props), value = _ref.value, mode = _ref.mode, prev = _ref.prev, next = _ref.next, total = _ref.total, pageSize = _ref.pageSize, itemSize = _ref.itemSize, onChange = _ref.onChange, ellipse = _ref.ellipse, itemRender = _ref.itemRender, defaultValue = _ref.defaultValue, className = _ref.className, style = _ref.style, rest = _object_without_properties(_ref, [
        "value",
        "mode",
        "prev",
        "next",
        "total",
        "pageSize",
        "itemSize",
        "onChange",
        "ellipse",
        "itemRender",
        "defaultValue",
        "className",
        "style"
    ]);
    var classPrefix = 'nut-pagination';
    var _usePropsValue = _sliced_to_array(usePropsValue({
        value: value,
        defaultValue: defaultValue,
        finalValue: 1,
        onChange: onChange
    }), 2), current = _usePropsValue[0], setCurrent = _usePropsValue[1];
    var _usePagination = _sliced_to_array(usePagination({
        total: total,
        ellipse: ellipse,
        current: current,
        displayCount: itemSize,
        itemsPerPage: pageSize
    }), 2), pages = _usePagination[0], pageCount = _usePagination[1];
    var handleClick = function(item) {
        if (item.selected) return;
        if (item.number > pageCount || item.number < 1) return;
        setCurrent(item.number);
    };
    var prevPage = function() {
        var prev = current - 1;
        prev >= 1 && setCurrent(prev);
    };
    var nextPage = function() {
        var next = current + 1;
        next <= pageCount && setCurrent(next);
    };
    var _obj, _obj1;
    return /*#__PURE__*/ React.createElement(View, {
        className: classNames(classPrefix, className),
        style: style
    }, (mode === 'multi' || mode === 'simple') && /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(View, {
        className: classNames((_obj = {}, _define_property(_obj, "".concat(classPrefix, "-prev"), true), _define_property(_obj, "".concat(classPrefix, "-simple-border"), mode !== 'multi'), _define_property(_obj, "".concat(classPrefix, "-prev-disabled"), current === 1), _obj)),
        onClick: function() {
            return prevPage();
        }
    }, addColorForHarmony(prev || locale.pagination.prev, current === 1 ? 'var(--nutui-color-text-disabled, #c2c4cc)' : 'var(--nutui-color-primary, #ff0f23)')), mode === 'multi' && /*#__PURE__*/ React.createElement(View, {
        className: "".concat(classPrefix, "-contain")
    }, pages.map(function(item, index) {
        var _obj;
        return /*#__PURE__*/ React.createElement(View, {
            key: "".concat(index, "pagination"),
            className: classNames((_obj = {}, _define_property(_obj, "".concat(classPrefix, "-item"), true), _define_property(_obj, "".concat(classPrefix, "-item-active"), item.selected), _obj)),
            onClick: function() {
                handleClick(item);
            }
        }, itemRender ? itemRender(item, current) : item.text);
    })), mode === 'simple' && /*#__PURE__*/ React.createElement(View, {
        className: "".concat(classPrefix, "-contain")
    }, /*#__PURE__*/ React.createElement(View, {
        className: "".concat(classPrefix, "-simple")
    }, "".concat(current, "/").concat(pageCount))), /*#__PURE__*/ React.createElement(View, {
        className: classNames((_obj1 = {}, _define_property(_obj1, "".concat(classPrefix, "-next"), true), _define_property(_obj1, "".concat(classPrefix, "-next-disabled"), current >= pageCount), _obj1)),
        onClick: function() {
            return nextPage();
        }
    }, addColorForHarmony(next || locale.pagination.next, current >= pageCount ? 'var(--nutui-color-text-disabled, #c2c4cc)' : 'var(--nutui-color-primary, #ff0f23)'))), mode === 'lite' && /*#__PURE__*/ React.createElement(View, {
        className: "".concat(classPrefix, "-lite")
    }, /*#__PURE__*/ React.createElement(Text, {
        className: "".concat(classPrefix, "-lite-active")
    }, current), /*#__PURE__*/ React.createElement(Text, {
        className: "".concat(classPrefix, "-lite-spliterator")
    }, "/"), /*#__PURE__*/ React.createElement(Text, {
        className: "".concat(classPrefix, "-lite-default")
    }, pageCount)));
};
Pagination.displayName = 'NutPagination';
