import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { cnb } from "cnbuilder";
import { Children, cloneElement, isValidElement } from "react";
/**
 * **Server Component**
 *
 * Note: This component **must** be rendered within a flex container unless the
 * {@link TextIconSpacingProps.forceIconWrap} is set to `true`.
 *
 * @example
 * Simple Example
 * ```tsx
 * import { TextIconSpacing, FontIcon } from "@react-md/core";
 * import type { ReactElement } from "react";
 *
 * function Example(): ReactElement {
 *   return (
 *     <TextIconSpacing icon={<FontIcon>favorite</FontIcon>}>
 *       Favorite
 *     </TextIconSpacing>
 *   );
 * }
 * ```
 *
 * @example
 * Stacked Example
 * ```tsx
 * import { TextIconSpacing, FontIcon } from "@react-md/core";
 * import type { ReactElement } from "react";
 *
 * function Example(): ReactElement {
 *   return (
 *     <TextIconSpacing icon={<FontIcon>favorite</FontIcon>} stacked>
 *       Favorite
 *     </TextIconSpacing>
 *   );
 * }
 * ```
 */ export function TextIconSpacing(props) {
    const { className, icon: propIcon, children = null, stacked = false, iconAfter = false, flexReverse = false, forceIconWrap = false, beforeClassName = "rmd-icon--before", afterClassName = "rmd-icon--after", aboveClassName = "rmd-icon--above", belowClassName = "rmd-icon--below" } = props;
    if (!propIcon) {
        return /*#__PURE__*/ _jsx(_Fragment, {
            children: children
        });
    }
    const isAfter = flexReverse ? !iconAfter : iconAfter;
    const baseClassName = cnb({
        [beforeClassName]: !stacked && !isAfter,
        [afterClassName]: !stacked && isAfter,
        [aboveClassName]: stacked && !isAfter,
        [belowClassName]: stacked && isAfter
    }, className);
    let iconEl = propIcon;
    let content = children;
    if (!forceIconWrap && /*#__PURE__*/ isValidElement(propIcon)) {
        const icon = Children.only(propIcon);
        iconEl = /*#__PURE__*/ cloneElement(icon, {
            className: cnb(baseClassName, icon.props.className)
        });
    } else if (propIcon) {
        iconEl = /*#__PURE__*/ _jsx("span", {
            className: cnb("rmd-text-icon-spacing", baseClassName),
            children: propIcon
        });
    }
    if (iconEl) {
        content = /*#__PURE__*/ _jsxs(_Fragment, {
            children: [
                !iconAfter && iconEl,
                children,
                iconAfter && iconEl
            ]
        });
    }
    return /*#__PURE__*/ _jsx(_Fragment, {
        children: content
    });
}

//# sourceMappingURL=TextIconSpacing.js.map