import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { cnb } from "cnbuilder";
import { forwardRef } from "react";
import { useEnsuredId } from "../useEnsuredId.js";
import { FormMessageContainer } from "./FormMessageContainer.js";
import { Label } from "./Label.js";
import { SwitchTrack } from "./SwitchTrack.js";
import { switchStyles } from "./switchStyles.js";
/**
 * **Server Component**
 *
 * @example
 * Simple Example
 * ```tsx
 * import { Form, Switch } from "@react-md/core";
 * import type { ReactElement } from "react";
 * import { useState } from "react";
 *
 * function Example(): ReactElement {
 *   const [checked, setChecked] = useState(false);
 *
 *   return (
 *     <Form>
 *       <Switch
 *         label="Label"
 *         name="enabled"
 *         checked={checked}
 *         onChange={(event) => setChecked(event.currentTarget.checked)}
 *       />
 *     </Form>
 *   );
 * }
 * ```
 *
 * @remarks \@since 6.0.0 Added support for `FormMessage` behavior.
 */ export const Switch = /*#__PURE__*/ forwardRef(function Switch(props, ref) {
    const { id: propId, label, labelProps, style, className, containerProps, ballProps, ballStyle, ballClassName, ballAddon, trackProps, trackStyle, trackClassName, messageProps, messageContainerProps, disableLabelGap = false, error = false, active = false, stacked = false, iconAfter = false, disabled = false, readOnly = false, ...remaining } = props;
    const id = useEnsuredId(propId, "switch");
    return /*#__PURE__*/ _jsx(FormMessageContainer, {
        ...messageContainerProps,
        messageProps: messageProps,
        children: /*#__PURE__*/ _jsxs(Label, {
            style: style,
            ...labelProps,
            className: cnb(className, labelProps?.className),
            gap: !disableLabelGap,
            stacked: stacked,
            reversed: !iconAfter,
            active: active,
            error: error,
            disabled: disabled,
            children: [
                label,
                /*#__PURE__*/ _jsx("div", {
                    ...containerProps,
                    className: switchStyles({
                        clickable: !disabled && !readOnly,
                        className: containerProps?.className,
                        currentColor: active || error
                    }),
                    children: /*#__PURE__*/ _jsx(SwitchTrack, {
                        style: trackStyle,
                        ...trackProps,
                        className: cnb(trackClassName, trackProps?.className),
                        disabled: disabled,
                        ballAddon: ballAddon,
                        ballProps: ballProps,
                        ballStyle: ballStyle,
                        ballClassName: ballClassName,
                        children: /*#__PURE__*/ _jsx("input", {
                            ...remaining,
                            id: id,
                            ref: ref,
                            role: "switch",
                            type: "checkbox",
                            className: cnb("rmd-switch__input rmd-hidden-input", disabled && "rmd-hidden-input--disabled"),
                            disabled: disabled
                        })
                    })
                })
            ]
        })
    });
});

//# sourceMappingURL=Switch.js.map