var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import { jsx as _jsx } from "react/jsx-runtime";
import { Pagination as BasePagination } from '@arco-design/web-react';
import { implementRuntimeComponent } from '@subscan/widget-runtime';
import { css, cx } from '@emotion/css';
import { Type } from '@sinclair/typebox';
import { FALLBACK_METADATA, getComponentProps, StringUnion } from 'utils/widget-helper';
import { useStateValue } from 'hooks/useStateValue';
import { VERSION, PRESET_PROPERTY_CATEGORY, COMPONENTS_CATEGORY } from 'config/constants';
import './index.css';
export var BasePaginationPropsSpec = {
    defaultCurrent: Type.Number({
        title: 'Default Page',
        category: PRESET_PROPERTY_CATEGORY.Basic,
    }),
    pageSize: Type.Number({
        title: 'Page Size',
        category: PRESET_PROPERTY_CATEGORY.Basic,
    }),
    total: Type.Number({
        title: 'Total',
        category: PRESET_PROPERTY_CATEGORY.Basic,
    }),
    updateWhenDefaultValueChanges: Type.Boolean({
        title: 'Update When Default Value Changes',
        category: PRESET_PROPERTY_CATEGORY.Basic,
    }),
    disabled: Type.Boolean({
        title: 'Disabled',
        category: PRESET_PROPERTY_CATEGORY.Behavior,
    }),
    hideOnSinglePage: Type.Boolean({
        title: 'Hide On Single Page',
        category: PRESET_PROPERTY_CATEGORY.Behavior,
    }),
    size: StringUnion(['mini', 'small', 'default', 'large'], {
        title: 'Size',
        category: PRESET_PROPERTY_CATEGORY.Style,
    }),
    sizeCanChange: Type.Boolean({
        title: 'Size Can Change',
        category: PRESET_PROPERTY_CATEGORY.Behavior,
    }),
    simple: Type.Boolean({
        title: 'Simple',
        category: PRESET_PROPERTY_CATEGORY.Behavior,
    }),
    showJumper: Type.Boolean({
        title: 'Show Jumper',
        category: PRESET_PROPERTY_CATEGORY.Behavior,
        description: 'Whether to display quick jump',
    }),
    showTotal: Type.Boolean({
        title: 'Show Total',
        category: PRESET_PROPERTY_CATEGORY.Behavior,
    }),
};
var PaginationPropsSpec = Type.Object(BasePaginationPropsSpec);
var PaginationStateSpec = Type.Object({
    currentPage: Type.Number(),
});
var exampleProperties = {
    pageSize: 10,
    total: 300,
    defaultCurrent: 3,
    disabled: false,
    hideOnSinglePage: true,
    size: 'default',
    sizeCanChange: false,
    simple: false,
    showJumper: false,
    showTotal: false,
    updateWhenDefaultValueChanges: false,
};
export default implementRuntimeComponent({
    version: VERSION.Core,
    metadata: __assign(__assign({}, FALLBACK_METADATA), { name: 'pagination', displayName: 'Pagination', exampleProperties: exampleProperties, annotations: {
            category: COMPONENTS_CATEGORY.Display,
        } }),
    spec: {
        properties: PaginationPropsSpec,
        state: PaginationStateSpec,
        methods: {},
        slots: {},
        styleSlots: ['content'],
        events: ['onChange'],
    },
})(function (props) {
    var _a = getComponentProps(props), defaultCurrent = _a.defaultCurrent, updateWhenDefaultValueChanges = _a.updateWhenDefaultValueChanges, cProps = __rest(_a, ["defaultCurrent", "updateWhenDefaultValueChanges"]);
    var elementRef = props.elementRef, customStyle = props.customStyle, mergeState = props.mergeState, callbackMap = props.callbackMap;
    var _b = useStateValue(defaultCurrent || 0, mergeState, updateWhenDefaultValueChanges, 'currentPage'), current = _b[0], setCurrent = _b[1];
    if (cProps.sizeCanChange) {
        Reflect.deleteProperty(cProps, 'pageSize');
    }
    var handleChange = function (pageNum) {
        var _a;
        setCurrent(pageNum);
        mergeState({ currentPage: pageNum });
        (_a = callbackMap === null || callbackMap === void 0 ? void 0 : callbackMap.onChange) === null || _a === void 0 ? void 0 : _a.call(callbackMap);
    };
    return (_jsx(BasePagination, __assign({ ref: elementRef, className: cx(css(customStyle === null || customStyle === void 0 ? void 0 : customStyle.content)) }, cProps, { current: current, onChange: handleChange })));
});
