"use client";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { forwardRef } from "react";
import { getIcon } from "../icon/config.js";
import { TableCellContent } from "./TableCellContent.js";
import { useTableConfig } from "./TableConfigurationProvider.js";
import { tableCell } from "./tableCellStyles.js";
/**
 * **Client Component**
 *
 * Creates a `<th>` or `<td>` cell with sensible styled defaults. You can create
 * a `<th>` element by enabling the `header` prop OR having a `TableCell` as a
 * child of the `TableHeader` component.
 *
 * Note: If you have a checkbox/radio column in the `TableHeader` without any
 * labels, you will need to manually set the `header={false}` prop for that cell
 * since it is invalid to have a `<th>` without any readable content for screen
 * readers.
 *
 * @see {@link https://react-md.dev/components/table | Table Demos}
 */ export const TableCell = /*#__PURE__*/ forwardRef(function TableCell(props, ref) {
    const { "aria-sort": sortOrder, className, grow = false, scope: propScope, hAlign: propHAlign, vAlign: propVAlign, header: propHeader, lineWrap: propDisableLineWrap, inputToggle, children, beforeChildren, afterChildren, sticky, sortIcon: propSortIcon, sortIconAfter = false, sortIconRotated, iconRotatorProps, padding = "horizontal", contentProps, ...remaining } = props;
    const sortIcon = getIcon("sort", propSortIcon);
    // Note: unlike the other usages of `useTableConfig`, the `propHeader`
    // is not provided. This is so that `TableCheckbox` components can still
    // be a sticky header without being rendered as a `<th>`. This also makes
    // it so the scope can be defaulted to `col` or `row` automatically.
    const { header: inheritedHeader, hAlign, vAlign, lineWrap } = useTableConfig({
        hAlign: propHAlign,
        vAlign: propVAlign,
        lineWrap: propDisableLineWrap
    });
    const header = propHeader ?? inheritedHeader;
    let scope = propScope;
    if (!scope && header) {
        scope = !inheritedHeader && propHeader ? "row" : "col";
    }
    const Component = header ? "th" : "td";
    return /*#__PURE__*/ _jsxs(Component, {
        ...remaining,
        ref: ref,
        "aria-sort": sortOrder === "none" ? undefined : sortOrder,
        className: tableCell({
            className,
            grow,
            header,
            sticky,
            inputToggle,
            hAlign,
            vAlign,
            lineWrap: !sortOrder && lineWrap,
            padding: sortIcon && sortOrder ? "none" : padding,
            isInTableHeader: inheritedHeader
        }),
        scope: scope,
        children: [
            beforeChildren,
            /*#__PURE__*/ _jsx(TableCellContent, {
                ...contentProps,
                icon: sortIcon,
                iconAfter: sortIconAfter,
                iconRotatorProps: iconRotatorProps,
                sortOrder: sortOrder,
                hAlign: hAlign,
                rotated: sortIconRotated,
                children: children
            }),
            afterChildren
        ]
    });
});

//# sourceMappingURL=TableCell.js.map