/*!
 * 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 { DataType } from '@datashaper/schema';
import { memo } from 'react';
import { Case, Default, Switch } from 'react-if';
import { categories, getValue, isBlank, isEmpty } from '../ArqueroDetailsList.utils.js';
import { useNumberMagnitude } from '../hooks/useNumberMagnitude.js';
import { ArrayDropdownCell } from './ArrayDropdownCell.js';
import { BlankCell } from './BlankCell.js';
import { CellContainer } from './CellContainer.js';
import { EmptyCell } from './EmptyCell.js';
import { BooleanSymbolCell, CategoricalBarCell, DateCell, DefaultCell, NumberMagnitudeCell, SparkbarCell, SparklineCell, TextCell } from './index.js';
/**
 * Chooses what to render based on the features prop
 */ export const FeaturesCell = /*#__PURE__*/ memo(function FeaturesCell(props) {
    const { features , field , item , column , index , onColumnClick  } = props;
    const type = field?.type;
    const value = getValue(item, column);
    const magnitude = useNumberMagnitude(value, field, type);
    const histo = categories(value);
    return /*#__PURE__*/ _jsx(CellContainer, {
        onClick: onColumnClick,
        column: column,
        children: /*#__PURE__*/ _jsxs(Switch, {
            children: [
                /*#__PURE__*/ _jsx(Case, {
                    condition: isBlank(value),
                    children: /*#__PURE__*/ _jsx(BlankCell, {})
                }),
                /*#__PURE__*/ _jsx(Case, {
                    condition: isEmpty(value),
                    children: /*#__PURE__*/ _jsx(EmptyCell, {
                        textAlign: type === DataType.Number || type === DataType.Boolean ? 'right' : 'left',
                        virtual: column?.data.virtual
                    })
                }),
                /*#__PURE__*/ _jsx(Case, {
                    condition: type === DataType.String,
                    children: /*#__PURE__*/ _jsx(TextCell, {
                        ...props
                    })
                }),
                /*#__PURE__*/ _jsx(Case, {
                    condition: features.showBooleanSymbol && type === DataType.Boolean,
                    children: /*#__PURE__*/ _jsx(BooleanSymbolCell, {
                        ...props
                    })
                }),
                /*#__PURE__*/ _jsx(Case, {
                    condition: features.showNumberMagnitude && type === DataType.Number,
                    children: /*#__PURE__*/ _jsx(NumberMagnitudeCell, {
                        ...props,
                        magnitude: magnitude
                    })
                }),
                /*#__PURE__*/ _jsx(Case, {
                    condition: features.showDateFormatted && type === DataType.Date,
                    children: /*#__PURE__*/ _jsx(DateCell, {
                        ...props
                    })
                }),
                /*#__PURE__*/ _jsx(Case, {
                    condition: features.showCategoricalBar && type === DataType.Array,
                    children: /*#__PURE__*/ _jsx(CategoricalBarCell, {
                        ...props,
                        categories: histo
                    })
                }),
                /*#__PURE__*/ _jsx(Case, {
                    condition: features.showSparkbar && type === DataType.Array && histo && histo['length' ?? 0],
                    children: /*#__PURE__*/ _jsx(SparkbarCell, {
                        ...props
                    })
                }),
                /*#__PURE__*/ _jsx(Case, {
                    condition: features.showDropdown && type === DataType.Array,
                    children: /*#__PURE__*/ _jsx(ArrayDropdownCell, {
                        rowIndex: index || 0,
                        ...props
                    })
                }),
                /*#__PURE__*/ _jsx(Case, {
                    condition: features.showSparkline && type === DataType.Array,
                    children: /*#__PURE__*/ _jsx(SparklineCell, {
                        ...props
                    })
                }),
                /*#__PURE__*/ _jsx(Default, {
                    children: /*#__PURE__*/ _jsx(DefaultCell, {
                        ...props
                    })
                })
            ]
        })
    });
});
