/*!
 * Copyright (c) Microsoft. All rights reserved.
 * Licensed under the MIT license. See LICENSE file in the project.
 */ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { memo } from 'react';
import { Case, Default, Switch } from 'react-if';
import { categories, getValue, isDistinctCategories } from '../ArqueroDetailsList.utils.js';
import { ArrayCell } from './ArrayCell.js';
import { ArrayDropdownCell } from './ArrayDropdownCell.js';
import { CategoricalBarCell, SparkbarCell, SparklineCell } from './index.js';
const HISTO_MAX = 20;
const DROPDOWN_MAX = 15;
/**
 * Chooses what sort of array display would be best.
 */ export const SmartArrayCell = /*#__PURE__*/ memo(function SmartArrayCell(props) {
    const { item , column , index  } = props;
    const values = getValue(item, column) || [];
    const cellWidth = column?.currentWidth || 0;
    const histo = categories(values);
    const histoLength = Object.keys(histo).length;
    const dist = isDistinctCategories(histo);
    return /*#__PURE__*/ _jsxs(Switch, {
        children: [
            /*#__PURE__*/ _jsx(Case, {
                condition: values.length <= 3,
                children: /*#__PURE__*/ _jsx(ArrayCell, {
                    ...props
                })
            }),
            /*#__PURE__*/ _jsx(Case, {
                condition: values.length <= DROPDOWN_MAX,
                children: /*#__PURE__*/ _jsx(ArrayDropdownCell, {
                    rowIndex: index || 0,
                    ...props
                })
            }),
            /*#__PURE__*/ _jsx(Case, {
                condition: histoLength <= HISTO_MAX && !dist,
                children: /*#__PURE__*/ _jsx(CategoricalBarCell, {
                    ...props,
                    categories: histo
                })
            }),
            /*#__PURE__*/ _jsx(Case, {
                condition: values.length <= cellWidth,
                children: /*#__PURE__*/ _jsx(SparkbarCell, {
                    ...props
                })
            }),
            /*#__PURE__*/ _jsx(Case, {
                condition: values.length > cellWidth,
                children: /*#__PURE__*/ _jsx(SparklineCell, {
                    ...props
                })
            }),
            /*#__PURE__*/ _jsx(Default, {
                children: /*#__PURE__*/ _jsx(ArrayCell, {
                    ...props
                })
            })
        ]
    });
});
