/*!
 * 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 { determineType } from '@datashaper/tables';
import { memo, useMemo } from 'react';
import { Case, Default, Switch } from 'react-if';
import { getValue, isBlank, isEmpty } from '../ArqueroDetailsList.utils.js';
import { ArrayCell } from './ArrayCell.js';
import { BlankCell } from './BlankCell.js';
import { BooleanTextCell, DateCell, EmptyCell, NumberCell, ObjectCell, TextCell } from './index.js';
/**
 * Default rendering of cell contents.
 * Designed to look like a basic Excel-style sheet (e.g., right-align numbers by default).
 * But with no fancy/costly visualization
 */ export const DefaultCell = /*#__PURE__*/ memo(function DefaultCell(props) {
    const { field , item , column , onColumnClick  } = props;
    const value = getValue(item, column);
    const type = field?.type || determineType(value);
    const cellStyle = useMemo(()=>{
        const style = {
            width: '100%'
        };
        if (onColumnClick) {
            style.cursor = 'pointer';
        }
        if (column?.data?.selected) {
            style.fontWeight = 'bold';
        }
        return style;
    }, [
        onColumnClick,
        column
    ]);
    return /*#__PURE__*/ _jsx("div", {
        style: cellStyle,
        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.Boolean,
                    children: /*#__PURE__*/ _jsx(BooleanTextCell, {
                        ...props
                    })
                }),
                /*#__PURE__*/ _jsx(Case, {
                    condition: type === DataType.String,
                    children: /*#__PURE__*/ _jsx(TextCell, {
                        ...props
                    })
                }),
                /*#__PURE__*/ _jsx(Case, {
                    condition: type === DataType.Number,
                    children: /*#__PURE__*/ _jsx(NumberCell, {
                        ...props,
                        numberFormat: ','
                    })
                }),
                /*#__PURE__*/ _jsx(Case, {
                    condition: type === DataType.Date,
                    children: /*#__PURE__*/ _jsx(DateCell, {
                        ...props
                    })
                }),
                /*#__PURE__*/ _jsx(Case, {
                    condition: type === DataType.Array,
                    children: /*#__PURE__*/ _jsx(ArrayCell, {
                        ...props
                    })
                }),
                /*#__PURE__*/ _jsx(Default, {
                    children: /*#__PURE__*/ _jsx(ObjectCell, {
                        ...props
                    })
                })
            ]
        })
    });
});
