import "./SegmentedControl.css";
import {centerBaseline as $1f4b04be3f24aae3$export$9d7e2342a7e53afa} from "./CenterBaseline.mjs";
import {IconContext as $ac8c32e6775ddd1f$export$a49f528ae1a4d0ed} from "../icons/Icon.mjs";
import {pressScale as $10ea7662e51a285b$export$56e8cba416805d8d} from "./pressScale.mjs";
import {Text as $8e847109a6ab556d$export$5f1af8db9871e1d6, TextContext as $8e847109a6ab556d$export$9afb8bc826b033ea} from "./Content.mjs";
import {useSpectrumContextProps as $5ce63c423902f47d$export$764f6146fadd77f7} from "../icons/useSpectrumContextProps.mjs";
import {jsx as $ae3Tm$jsx, jsxs as $ae3Tm$jsxs, Fragment as $ae3Tm$Fragment} from "react/jsx-runtime";
import {ToggleButtonGroup as $ae3Tm$ToggleButtonGroup, ToggleGroupStateContext as $ae3Tm$ToggleGroupStateContext, Provider as $ae3Tm$Provider, ToggleButton as $ae3Tm$ToggleButton, SelectionIndicator as $ae3Tm$SelectionIndicator, TextContext as $ae3Tm$TextContext, DEFAULT_SLOT as $ae3Tm$DEFAULT_SLOT} from "react-aria-components";
import {createContext as $ae3Tm$createContext, forwardRef as $ae3Tm$forwardRef, useContext as $ae3Tm$useContext, useRef as $ae3Tm$useRef, useCallback as $ae3Tm$useCallback} from "react";
import {useDOMRef as $ae3Tm$useDOMRef, useFocusableRef as $ae3Tm$useFocusableRef} from "@react-spectrum/utils";
import {useLayoutEffect as $ae3Tm$useLayoutEffect} from "@react-aria/utils";

/*
 * Copyright 2024 Adobe. All rights reserved.
 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy
 * of the License at http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
 * OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */ 









const $c679c2152e03f8bf$export$c083c44d8a07dd35 = /*#__PURE__*/ (0, $ae3Tm$createContext)(null);
const $c679c2152e03f8bf$var$segmentedControl = function anonymous(props, overrides) {
    let rules = " ";
    let width = false;
    let matches = String(overrides || '').matchAll(/(?:^|\s)(J|G|I|H|_u|_v|_s|__A|_d|_J|z|y|B|A|_P|_9|W|_l|_A|_z|_6|Z|N|L)[^\s]+/g);
    for (let p of matches){
        if (p[1] === "Z") width = true;
        rules += p[0];
    }
    rules += ' sd11';
    rules += ' Ub11';
    rules += ' qb11';
    rules += ' gH11';
    rules += ' ob11';
    rules += ' nb11';
    rules += ' kb11';
    rules += ' jb11';
    if (!width) rules += ' ZJ11';
    return rules;
};
const $c679c2152e03f8bf$var$controlItem = function anonymous(props, overrides) {
    let rules = " ";
    let minWidth = false;
    let position = false;
    let flexGrow = false;
    let flexBasis = false;
    let flexShrink = false;
    let zIndex = false;
    let matches = String(overrides || '').matchAll(/(?:^|\s)(J|G|I|H|_u|_v|_s|__A|_d|_J|z|y|B|A|_P|_9|W|_l|_A|_z|_6|Z|N|L)[^\s]+/g);
    for (let p of matches){
        if (p[1] === "N") minWidth = true;
        if (p[1] === "_P") position = true;
        if (p[1] === "_u") flexGrow = true;
        if (p[1] === "_s") flexBasis = true;
        if (p[1] === "_v") flexShrink = true;
        if (p[1] === "_9") zIndex = true;
        rules += p[0];
    }
    if (props.isFocusVisible) rules += ' _Lf11';
    else rules += ' _Le11';
    rules += ' Oh11';
    rules += ' Olc11';
    rules += ' _Mc11';
    rules += ' _Kd11';
    if (props.size === "XL") {
        rules += ' uk11';
        rules += ' ucJ9TBTb11';
        rules += ' ud3Euai11';
        rules += ' uea11';
        rules += ' ugb11';
        rules += ' uhd11';
        rules += ' uje11';
        rules += ' u2NhKxcl11';
        rules += ' uic11';
    } else if (props.size === "L") {
        rules += ' uk11';
        rules += ' ucJ9TBTb11';
        rules += ' ud3Euai11';
        rules += ' uea11';
        rules += ' ugb11';
        rules += ' uhd11';
        rules += ' uje11';
        rules += ' u2NhKxcl11';
        rules += ' uic11';
    } else if (props.size === "S") {
        rules += ' uk11';
        rules += ' ucJ9TBTb11';
        rules += ' ud3Euai11';
        rules += ' uea11';
        rules += ' ugb11';
        rules += ' uhd11';
        rules += ' uje11';
        rules += ' u2NhKxcl11';
        rules += ' uic11';
    } else if (props.size === "XS") {
        rules += ' uk11';
        rules += ' ucJ9TBTb11';
        rules += ' ud3Euai11';
        rules += ' uea11';
        rules += ' ugb11';
        rules += ' uhd11';
        rules += ' uje11';
        rules += ' u2NhKxcl11';
        rules += ' uic11';
    } else {
        rules += ' uk11';
        rules += ' ucJ9TBTb11';
        rules += ' ud3Euai11';
        rules += ' uea11';
        rules += ' ugb11';
        rules += ' uhd11';
        rules += ' uje11';
        rules += ' u2NhKxcl11';
        rules += ' uic11';
    }
    if (props.size === "XL") {
        rules += ' -_6BNtrc-e11';
        rules += ' vx11';
    } else if (props.size === "L") {
        rules += ' -_6BNtrc-d11';
        rules += ' vx11';
    } else if (props.size === "S") {
        rules += ' -_6BNtrc-b11';
        rules += ' vx11';
    } else if (props.size === "XS") {
        rules += ' -_6BNtrc-a11';
        rules += ' vx11';
    } else {
        rules += ' -_6BNtrc-c11';
        rules += ' vx11';
    }
    if (props.size === "XL") {
        rules += ' xb11';
        rules += ' _xa11';
    } else if (props.size === "L") {
        rules += ' xb11';
        rules += ' _xa11';
    } else if (props.size === "S") {
        rules += ' xb11';
        rules += ' _xa11';
    } else if (props.size === "XS") {
        rules += ' xb11';
        rules += ' _xa11';
    } else {
        rules += ' xb11';
        rules += ' _xa11';
    }
    if (props.size === "XL") {
        rules += ' _Fd11';
        rules += ' _FnuYUweb11';
    } else if (props.size === "L") {
        rules += ' _Fd11';
        rules += ' _FnuYUweb11';
    } else if (props.size === "S") {
        rules += ' _Fd11';
        rules += ' _FnuYUweb11';
    } else if (props.size === "XS") {
        rules += ' _Fd11';
        rules += ' _FnuYUweb11';
    } else {
        rules += ' _Fd11';
        rules += ' _FnuYUweb11';
    }
    if (props.isDisabled) rules += ' pp11';
    else if (props.isSelected) {
        if (props.isPressed) rules += ' po11';
        else if (props.isFocusVisible) rules += ' po11';
        else if (props.isHovered) rules += ' po11';
        else rules += ' pt11';
    } else {
        if (props.isPressed) rules += ' pt11';
        else if (props.isFocusVisible) rules += ' pt11';
        else if (props.isHovered) rules += ' pt11';
        else rules += ' pv11';
    }
    if (props.isSelected) rules += ' ple11';
    else if (props.isDisabled) rules += ' plc11';
    else rules += ' plb11';
    rules += ' sd11';
    rules += ' eb11';
    rules += ' _oa11';
    rules += ' Sv11';
    rules += ' SgLWx3bd11';
    rules += ' Rv11';
    rules += ' RgLWx3bd11';
    if (props.size === "XL") {
        if (!minWidth) rules += ' Nl11';
    } else if (props.size === "L") {
        if (!minWidth) rules += ' Nj11';
    } else if (props.size === "S") {
        if (!minWidth) rules += ' Nf11';
    } else if (props.size === "XS") {
        if (!minWidth) rules += ' Ne11';
    } else if (!minWidth) rules += ' Nk11';
    if (props.size === "XL") rules += ' -SFnbic-_JaP8ec11';
    else if (props.size === "L") rules += ' -SFnbic-_J0K2hn11';
    else if (props.size === "S") rules += ' -SFnbic-_JJOW22b11';
    else if (props.size === "XS") rules += ' -SFnbic-_JICefdd11';
    else rules += ' -SFnbic-_Jb11';
    rules += ' -Bu7z1c-ob11';
    rules += ' oj11';
    rules += ' nj11';
    rules += ' kj11';
    rules += ' jj11';
    rules += ' qc11';
    rules += ' qsd11';
    rules += ' -Qg41Lb-IAxCW0c11';
    rules += ' -Qg41Lb-gLWx3bIy11';
    rules += ' FRuFGYc11';
    rules += ' _Ca11';
    if (!position) rules += ' _Pc11';
    rules += ' _yb11';
    if (props.isJustified) {
        if (!flexGrow) rules += ' _ub11';
    }
    if (props.isJustified) {
        if (!flexBasis) rules += ' _sb11';
    }
    if (!flexShrink) rules += ' _va11';
    rules += ' _7c11';
    rules += ' __ca11';
    rules += ' _4c11';
    rules += ' g911';
    rules += ' _je11';
    rules += ' -_8sjo0b-t5ZbAob11';
    if (props.isSelected) {
        if (!zIndex) rules += ' _9b11';
    } else if (!zIndex) rules += ' _9c11';
    if (props.size === "XL") rules += ' -F_-Fz11';
    else if (props.size === "L") rules += ' -F_-Fv11';
    else if (props.size === "S") rules += ' -F_-Fp11';
    else if (props.size === "XS") rules += ' -F_-Fn11';
    else rules += ' -F_-Fx11';
    return rules;
};
const $c679c2152e03f8bf$var$slider = function anonymous(props) {
    let rules = " ";
    rules += ' gX11';
    if (props.isDisabled) rules += ' gld11';
    else rules += ' gle11';
    rules += ' Wr11';
    rules += ' _Er11';
    rules += ' Za11';
    rules += ' Fb11';
    rules += ' _qg11';
    rules += ' Yx6BKnd11';
    rules += ' Ydklsgce11';
    rules += ' Xc11';
    rules += ' _2a11';
    rules += ' _Pa11';
    rules += ' _oa11';
    rules += ' _jf11';
    rules += ' _kc11';
    rules += ' hc11';
    rules += ' mc11';
    rules += ' lc11';
    if (props.isDisabled) rules += ' iq11';
    else rules += ' in11';
    if (props.isDisabled) rules += ' ilc11';
    else rules += ' ild11';
    rules += ' oc11';
    rules += ' nc11';
    rules += ' kc11';
    rules += ' jc11';
    return rules;
};
const $c679c2152e03f8bf$var$InternalSegmentedControlContext = /*#__PURE__*/ (0, $ae3Tm$createContext)({});
const $c679c2152e03f8bf$export$668709c620d0b8e2 = /*#__PURE__*/ (0, $ae3Tm$forwardRef)(function SegmentedControl(props, ref) {
    [props, ref] = (0, $5ce63c423902f47d$export$764f6146fadd77f7)(props, ref, $c679c2152e03f8bf$export$c083c44d8a07dd35);
    let { defaultSelectedKey: defaultSelectedKey, selectedKey: selectedKey, onSelectionChange: onSelectionChange } = props;
    let domRef = (0, $ae3Tm$useDOMRef)(ref);
    let onChange = (values)=>{
        if (onSelectionChange) {
            let firstKey = values.values().next().value;
            if (firstKey != null) onSelectionChange(firstKey);
        }
    };
    return /*#__PURE__*/ (0, $ae3Tm$jsx)((0, $ae3Tm$ToggleButtonGroup), {
        ...props,
        selectedKeys: selectedKey != null ? [
            selectedKey
        ] : undefined,
        defaultSelectedKeys: defaultSelectedKey != null ? [
            defaultSelectedKey
        ] : undefined,
        disallowEmptySelection: true,
        ref: domRef,
        orientation: "horizontal",
        style: props.UNSAFE_style,
        onSelectionChange: onChange,
        className: (props.UNSAFE_className || '') + $c679c2152e03f8bf$var$segmentedControl(null, props.styles),
        "aria-label": props['aria-label'],
        children: /*#__PURE__*/ (0, $ae3Tm$jsx)($c679c2152e03f8bf$var$DefaultSelectionTracker, {
            defaultValue: defaultSelectedKey,
            value: selectedKey,
            isJustified: props.isJustified,
            children: props.children
        })
    });
});
function $c679c2152e03f8bf$var$DefaultSelectionTracker(props) {
    let state = (0, $ae3Tm$useContext)((0, $ae3Tm$ToggleGroupStateContext));
    let isRegistered = (0, $ae3Tm$useRef)(!(props.defaultValue == null && props.value == null));
    // default select the first available item
    let register = (0, $ae3Tm$useCallback)((value)=>{
        if (state && !isRegistered.current) {
            isRegistered.current = true;
            state.toggleKey(value);
        }
    // eslint-disable-next-line react-hooks/exhaustive-deps
    }, []);
    return /*#__PURE__*/ (0, $ae3Tm$jsx)((0, $ae3Tm$Provider), {
        values: [
            [
                $c679c2152e03f8bf$var$InternalSegmentedControlContext,
                {
                    register: register,
                    isJustified: props.isJustified
                }
            ]
        ],
        children: props.children
    });
}
const $c679c2152e03f8bf$export$4fc12f2742e8cf3f = /*#__PURE__*/ (0, $ae3Tm$forwardRef)(function SegmentedControlItem(props, ref) {
    let domRef = (0, $ae3Tm$useFocusableRef)(ref);
    let divRef = (0, $ae3Tm$useRef)(null);
    let { register: register, isJustified: isJustified } = (0, $ae3Tm$useContext)($c679c2152e03f8bf$var$InternalSegmentedControlContext);
    (0, $ae3Tm$useLayoutEffect)(()=>{
        register?.(props.id);
    }, [
        register,
        props.id
    ]);
    return /*#__PURE__*/ (0, $ae3Tm$jsx)((0, $ae3Tm$ToggleButton), {
        ...props,
        ref: domRef,
        style: props.UNSAFE_style,
        className: (renderProps)=>(props.UNSAFE_className || '') + $c679c2152e03f8bf$var$controlItem({
                ...renderProps,
                isJustified: isJustified
            }, props.styles),
        children: ({ isPressed: isPressed, isDisabled: isDisabled })=>/*#__PURE__*/ (0, $ae3Tm$jsxs)((0, $ae3Tm$Fragment), {
                children: [
                    /*#__PURE__*/ (0, $ae3Tm$jsx)((0, $ae3Tm$SelectionIndicator), {
                        className: $c679c2152e03f8bf$var$slider({
                            isDisabled: isDisabled
                        })
                    }),
                    /*#__PURE__*/ (0, $ae3Tm$jsx)((0, $ae3Tm$Provider), {
                        values: [
                            [
                                (0, $ac8c32e6775ddd1f$export$a49f528ae1a4d0ed),
                                {
                                    render: (0, $1f4b04be3f24aae3$export$9d7e2342a7e53afa)({
                                        slot: 'icon',
                                        styles: " _Ja11 _va11"
                                    })
                                }
                            ],
                            [
                                (0, $ae3Tm$TextContext),
                                {
                                    slots: {
                                        [(0, $ae3Tm$DEFAULT_SLOT)]: {}
                                    }
                                }
                            ],
                            [
                                (0, $8e847109a6ab556d$export$9afb8bc826b033ea),
                                {
                                    styles: " _Jb11 _Nc11 Pc11 _Yb11 _7c11"
                                }
                            ]
                        ],
                        children: /*#__PURE__*/ (0, $ae3Tm$jsx)("div", {
                            ref: divRef,
                            style: (0, $10ea7662e51a285b$export$56e8cba416805d8d)(divRef)({
                                isPressed: isPressed
                            }),
                            className: " sd11 Uc11 Usd11 qc11 qsd11 Yd11 Xb11 _2b11 eb11 Na11",
                            children: typeof props.children === 'string' ? /*#__PURE__*/ (0, $ae3Tm$jsx)((0, $8e847109a6ab556d$export$5f1af8db9871e1d6), {
                                children: props.children
                            }) : props.children
                        })
                    })
                ]
            })
    });
});


export {$c679c2152e03f8bf$export$c083c44d8a07dd35 as SegmentedControlContext, $c679c2152e03f8bf$export$668709c620d0b8e2 as SegmentedControl, $c679c2152e03f8bf$export$4fc12f2742e8cf3f as SegmentedControlItem};
//# sourceMappingURL=SegmentedControl.mjs.map
