"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Pagination = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const Pagination = ({ currentPage, totalPages, onPageChange, className, showFirstLast = true, showPrevNext = true, siblingCount = 1, boundaryCount = 1, size = 'md', variant = 'default', disabled = false, compact = false, ariaLabel = 'Pagination', }) => {
    const handlePageChange = (page) => {
        if (disabled || page < 1 || page > totalPages || page === currentPage) {
            return;
        }
        onPageChange(page);
    };
    const renderPaginationItem = ({ page, isActive = false, isDisabled = false, onClick, children, className: itemClassName, ariaLabel: itemAriaLabel, }) => {
        const itemClasses = [
            'bf-pagination__item',
            isActive ? 'bf-pagination__item--active' : '',
            isDisabled ? 'bf-pagination__item--disabled' : '',
            `bf-pagination__item--${size}`,
            `bf-pagination__item--${variant}`,
            itemClassName || '',
        ].filter(Boolean).join(' ');
        return ((0, jsx_runtime_1.jsx)("li", { className: "bf-pagination__list-item", children: (0, jsx_runtime_1.jsx)("button", { className: itemClasses, onClick: onClick, disabled: isDisabled || disabled, "aria-current": isActive ? 'page' : undefined, "aria-label": itemAriaLabel, tabIndex: isDisabled || disabled ? -1 : 0, children: children || page }) }));
    };
    const generatePaginationItems = () => {
        const items = [];
        // Helper to add a range of items
        const addRange = (start, end) => {
            for (let i = start; i <= end; i++) {
                items.push(renderPaginationItem({
                    page: i,
                    isActive: i === currentPage,
                    onClick: () => handlePageChange(i),
                    ariaLabel: `Go to page ${i}`,
                }));
            }
        };
        // Helper to add ellipsis
        const addEllipsis = (key) => {
            items.push((0, jsx_runtime_1.jsx)("li", { className: "bf-pagination__ellipsis", "aria-hidden": "true", children: (0, jsx_runtime_1.jsx)("span", { className: "bf-pagination__ellipsis-dots", children: "..." }) }, key));
        };
        // Always show first page
        if (showFirstLast) {
            items.push(renderPaginationItem({
                page: 1,
                isDisabled: currentPage === 1,
                onClick: () => handlePageChange(1),
                ariaLabel: 'Go to first page',
                children: '«',
            }));
        }
        // Show previous page button
        if (showPrevNext) {
            items.push(renderPaginationItem({
                page: currentPage - 1,
                isDisabled: currentPage === 1,
                onClick: () => handlePageChange(currentPage - 1),
                ariaLabel: 'Go to previous page',
                children: '‹',
            }));
        }
        // Calculate range of pages to show
        const leftSiblingIndex = Math.max(currentPage - siblingCount, 1);
        const rightSiblingIndex = Math.min(currentPage + siblingCount, totalPages);
        // Always show first boundaryCount pages
        if (leftSiblingIndex > boundaryCount + 1) {
            addRange(1, boundaryCount);
            addEllipsis('left-ellipsis');
        }
        // Show pages around current page
        addRange(leftSiblingIndex, rightSiblingIndex);
        // Always show last boundaryCount pages
        if (rightSiblingIndex < totalPages - boundaryCount) {
            addEllipsis('right-ellipsis');
            addRange(totalPages - boundaryCount + 1, totalPages);
        }
        // Show next page button
        if (showPrevNext) {
            items.push(renderPaginationItem({
                page: currentPage + 1,
                isDisabled: currentPage === totalPages,
                onClick: () => handlePageChange(currentPage + 1),
                ariaLabel: 'Go to next page',
                children: '›',
            }));
        }
        // Always show last page
        if (showFirstLast) {
            items.push(renderPaginationItem({
                page: totalPages,
                isDisabled: currentPage === totalPages,
                onClick: () => handlePageChange(totalPages),
                ariaLabel: 'Go to last page',
                children: '»',
            }));
        }
        return items;
    };
    const paginationClasses = [
        'bf-pagination',
        compact ? 'bf-pagination--compact' : '',
        disabled ? 'bf-pagination--disabled' : '',
        className || '',
    ].filter(Boolean).join(' ');
    return ((0, jsx_runtime_1.jsx)("nav", { className: paginationClasses, "aria-label": ariaLabel, children: (0, jsx_runtime_1.jsx)("ul", { className: "bf-pagination__list", children: generatePaginationItems() }) }));
};
exports.Pagination = Pagination;
exports.default = exports.Pagination;
//# sourceMappingURL=Pagination.js.map