import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { cnb } from "cnbuilder";
import { forwardRef } from "react";
import { ButtonUnstyled } from "../button/ButtonUnstyled.js";
import { IconRotator } from "../icon/IconRotator.js";
import { bem } from "../utils/bem.js";
const styles = bem("rmd-table-cell");
/**
 * **Server Component**
 * This might actually be a client component.
 *
 * This is mostly an internal component since it is automatically used within
 * the `TableCell` component but this will conditionally wrap the `children`
 * within an `UnstyledButton` to make a clickable cell. This is really to help
 * with sort behavior within headers.
 *
 * @internal
 */ export const TableCellContent = /*#__PURE__*/ forwardRef(function TableCellContent(props, ref) {
    const { icon: propIcon, style, className, sortOrder, children, rotated: propRotated, hAlign = "left", iconAfter, iconRotatorProps, ...remaining } = props;
    if (!sortOrder || propIcon === null) {
        return /*#__PURE__*/ _jsx(_Fragment, {
            children: children
        });
    }
    let icon = null;
    if (sortOrder !== "none") {
        const rotated = propRotated ?? sortOrder === "descending";
        icon = /*#__PURE__*/ _jsx(IconRotator, {
            ...iconRotatorProps,
            rotated: rotated,
            children: propIcon
        });
    }
    return /*#__PURE__*/ _jsxs(ButtonUnstyled, {
        ...remaining,
        ref: ref,
        style: style,
        className: cnb(styles("content", {
            [hAlign]: hAlign !== "left"
        }), className),
        children: [
            !iconAfter && icon,
            children,
            iconAfter && icon
        ]
    });
});

//# sourceMappingURL=TableCellContent.js.map