import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
import { createContext, forwardRef, useContext, useRef, useId } from 'react';
import { c as cx } from './index-De1g9FRV.js';
import { D as Duration } from './primitive-C3RFDRA8.js';
import { I as Icon } from './Icon-DuIlne4x.js';
import { u as useReducedMotion } from './use-reduced-motion-CqjZZ5QB.js';
import { useTrackingId } from './useTrackingId.js';
import { u as useMergeRefs } from './useMergeRefs-Dfmtq9cI.js';
import { m as motion } from './proxy-DEehATlA.js';
import { u as useOptionallyControlledState } from './useOptionallyControlledState-DbDuos5L.js';

import './SegmentedControl.css';const SegmentedControlContext = createContext({});

const legend = "_legend_1jy4v_3";
const children = "_children_1jy4v_4";
const segment = "_segment_1jy4v_2";
const fill = "_fill_1jy4v_80";
const small = "_small_1jy4v_83";
const medium = "_medium_1jy4v_92";
const styles = {
	"segmented-control": "_segmented-control_1jy4v_2",
	legend: legend,
	children: children,
	"select-indicator": "_select-indicator_1jy4v_5",
	segment: segment,
	fill: fill,
	small: small,
	"icon-only": "_icon-only_1jy4v_89",
	medium: medium
};

const SegmentedControlSegment = forwardRef((props, ref) => {
  const {
    icon,
    value,
    children,
    className,
    "aria-label": ariaLabel,
    ...rest
  } = props;
  const shouldReduceMotion = useReducedMotion();
  const { current, setCurrent, name } = useContext(SegmentedControlContext);
  const labelRef = useRef(null);
  const classNames = cx(styles.segment, className, {
    [styles["icon-only"]]: icon && !children
  });
  const data = {
    value: props.value
  };
  const trackingId = useTrackingId({
    name: "SegmentedControlSegment",
    data,
    hasOverride: !!props["data-tracking-id"]
  });
  const computedAriaLabel = !children ? ariaLabel || value : void 0;
  return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(
    "label",
    {
      className: classNames,
      ref: useMergeRefs([labelRef, ref]),
      "data-tracking-id": trackingId,
      "data-anv": "segmented-control-segment",
      "aria-label": computedAriaLabel,
      ...rest,
      children: [
        /* @__PURE__ */ jsx(
          "input",
          {
            type: "radio",
            name,
            value,
            onChange: () => setCurrent?.(value),
            checked: current === value,
            "aria-checked": current === value
          }
        ),
        icon ? /* @__PURE__ */ jsx(Icon, { svg: icon, "aria-hidden": true }) : null,
        children,
        current === value && /* @__PURE__ */ jsx(
          motion.span,
          {
            layoutId: name,
            className: styles["select-indicator"],
            transition: {
              duration: shouldReduceMotion ? 0 : +Duration.value.replace("ms", "") / 1e3
            }
          }
        )
      ]
    }
  ) });
});
SegmentedControlSegment.displayName = "SegmentedControlSegment";

const SegmentedControl = Object.assign(
  forwardRef(
    function SegmentedControlInner(props, ref) {
      const {
        className,
        onClick,
        onChange,
        children,
        size = "medium",
        defaultSelected,
        selected,
        name,
        fill,
        ...rest
      } = props;
      const [current, setCurrent] = useOptionallyControlledState({
        controlledValue: selected,
        defaultValue: defaultSelected,
        onChange
      });
      const segmentedControlRef = useRef(null);
      const SegmentedControlClassNames = cx(
        styles["segmented-control"],
        styles[size],
        className,
        {
          [styles.fill]: fill
        }
      );
      const uid = useId();
      const data = {
        name: props.name
      };
      const trackingId = useTrackingId({
        name: "SegmentedControl",
        data,
        hasOverride: !!props["data-tracking-id"]
      });
      return /* @__PURE__ */ jsx(
        motion.div,
        {
          transition: { duration: 0 },
          layout: true,
          role: "radiogroup",
          className: SegmentedControlClassNames,
          "data-anv": "segmented-control",
          "data-tracking-id": trackingId,
          ref: useMergeRefs([segmentedControlRef, ref]),
          ...rest,
          children: /* @__PURE__ */ jsx(
            SegmentedControlContext.Provider,
            {
              value: { current, setCurrent, name: name ?? uid },
              children
            }
          )
        }
      );
    }
  ),
  {
    /**
     * SegmentedControlSegment component for individual segments within a segmented control.
     *
     * Features:
     * - Individual segment with radio input
     * - Optional icon support
     * - Animated selection indicator
     * - Accessibility support with proper ARIA attributes
     * - Context integration with parent SegmentedControl
     * - Motion animations with reduced motion support
     *
     * @example
     * <SegmentedControl.Segment value="option1" icon={Icon1}>
     *   Option 1
     * </SegmentedControl.Segment>
     */
    Segment: SegmentedControlSegment
  }
);
SegmentedControl.displayName = "SegmentedControl";

export { SegmentedControl as S, SegmentedControlSegment as a };
//# sourceMappingURL=SegmentedControl-B9NWUF7s.js.map
