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 = (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 += ' sd1';
    rules += ' Ub1';
    rules += ' qb1';
    rules += ' gH1';
    rules += ' ob1';
    rules += ' nb1';
    rules += ' kb1';
    rules += ' jb1';
    if (!width) rules += ' ZJ1';
    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 = (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 += ' _Lf1';
    else rules += ' _Le1';
    rules += ' Oh1';
    rules += ' Olc1';
    rules += ' _Mc1';
    rules += ' _Kd1';
    if (props.size === "XL") {
        rules += ' uk1';
        rules += ' ucJ9TBTb1';
        rules += ' ud3Euai1';
        rules += ' uea1';
        rules += ' ugb1';
        rules += ' uhd1';
        rules += ' uje1';
        rules += ' u2NhKxcl1';
        rules += ' uic1';
    } else if (props.size === "L") {
        rules += ' uk1';
        rules += ' ucJ9TBTb1';
        rules += ' ud3Euai1';
        rules += ' uea1';
        rules += ' ugb1';
        rules += ' uhd1';
        rules += ' uje1';
        rules += ' u2NhKxcl1';
        rules += ' uic1';
    } else if (props.size === "S") {
        rules += ' uk1';
        rules += ' ucJ9TBTb1';
        rules += ' ud3Euai1';
        rules += ' uea1';
        rules += ' ugb1';
        rules += ' uhd1';
        rules += ' uje1';
        rules += ' u2NhKxcl1';
        rules += ' uic1';
    } else if (props.size === "XS") {
        rules += ' uk1';
        rules += ' ucJ9TBTb1';
        rules += ' ud3Euai1';
        rules += ' uea1';
        rules += ' ugb1';
        rules += ' uhd1';
        rules += ' uje1';
        rules += ' u2NhKxcl1';
        rules += ' uic1';
    } else {
        rules += ' uk1';
        rules += ' ucJ9TBTb1';
        rules += ' ud3Euai1';
        rules += ' uea1';
        rules += ' ugb1';
        rules += ' uhd1';
        rules += ' uje1';
        rules += ' u2NhKxcl1';
        rules += ' uic1';
    }
    if (props.size === "XL") {
        rules += ' -_6BNtrc-e1';
        rules += ' vx1';
    } else if (props.size === "L") {
        rules += ' -_6BNtrc-d1';
        rules += ' vx1';
    } else if (props.size === "S") {
        rules += ' -_6BNtrc-b1';
        rules += ' vx1';
    } else if (props.size === "XS") {
        rules += ' -_6BNtrc-a1';
        rules += ' vx1';
    } else {
        rules += ' -_6BNtrc-c1';
        rules += ' vx1';
    }
    if (props.size === "XL") {
        rules += ' xb1';
        rules += ' _xa1';
    } else if (props.size === "L") {
        rules += ' xb1';
        rules += ' _xa1';
    } else if (props.size === "S") {
        rules += ' xb1';
        rules += ' _xa1';
    } else if (props.size === "XS") {
        rules += ' xb1';
        rules += ' _xa1';
    } else {
        rules += ' xb1';
        rules += ' _xa1';
    }
    if (props.size === "XL") {
        rules += ' _Fd1';
        rules += ' _FnuYUweb1';
    } else if (props.size === "L") {
        rules += ' _Fd1';
        rules += ' _FnuYUweb1';
    } else if (props.size === "S") {
        rules += ' _Fd1';
        rules += ' _FnuYUweb1';
    } else if (props.size === "XS") {
        rules += ' _Fd1';
        rules += ' _FnuYUweb1';
    } else {
        rules += ' _Fd1';
        rules += ' _FnuYUweb1';
    }
    if (props.isDisabled) rules += ' pp1';
    else if (props.isSelected) {
        if (props.isPressed) rules += ' po1';
        else if (props.isFocusVisible) rules += ' po1';
        else if (props.isHovered) rules += ' po1';
        else rules += ' pt1';
    } else {
        if (props.isPressed) rules += ' pt1';
        else if (props.isFocusVisible) rules += ' pt1';
        else if (props.isHovered) rules += ' pt1';
        else rules += ' pv1';
    }
    if (props.isSelected) rules += ' ple1';
    else if (props.isDisabled) rules += ' plc1';
    else rules += ' plb1';
    rules += ' sd1';
    rules += ' eb1';
    rules += ' _oa1';
    rules += ' Sv1';
    rules += ' SgLWx3bd1';
    rules += ' Rv1';
    rules += ' RgLWx3bd1';
    if (props.size === "XL") {
        if (!minWidth) rules += ' Nl1';
    } else if (props.size === "L") {
        if (!minWidth) rules += ' Nj1';
    } else if (props.size === "S") {
        if (!minWidth) rules += ' Nf1';
    } else if (props.size === "XS") {
        if (!minWidth) rules += ' Ne1';
    } else if (!minWidth) rules += ' Nk1';
    if (props.size === "XL") rules += ' -SFnbic-_JaP8ec1';
    else if (props.size === "L") rules += ' -SFnbic-_J0K2hn1';
    else if (props.size === "S") rules += ' -SFnbic-_JJOW22b1';
    else if (props.size === "XS") rules += ' -SFnbic-_JICefdd1';
    else rules += ' -SFnbic-_Jb1';
    rules += ' -Bu7z1c-ob1';
    rules += ' oj1';
    rules += ' nj1';
    rules += ' kj1';
    rules += ' jj1';
    rules += ' qc1';
    rules += ' qsd1';
    rules += ' -Qg41Lb-IAxCW0c1';
    rules += ' -Qg41Lb-gLWx3bIy1';
    rules += ' FRuFGYc1';
    rules += ' _Ca1';
    if (!position) rules += ' _Pc1';
    rules += ' _yb1';
    if (props.isJustified) {
        if (!flexGrow) rules += ' _ub1';
    }
    if (props.isJustified) {
        if (!flexBasis) rules += ' _sb1';
    }
    if (!flexShrink) rules += ' _va1';
    rules += ' _7c1';
    rules += ' __ca1';
    rules += ' _4c1';
    rules += ' g91';
    rules += ' _je1';
    rules += ' -_8sjo0b-t5ZbAob1';
    if (props.isSelected) {
        if (!zIndex) rules += ' _9b1';
    } else if (!zIndex) rules += ' _9c1';
    if (props.size === "XL") rules += ' -F_-Fz1';
    else if (props.size === "L") rules += ' -F_-Fv1';
    else if (props.size === "S") rules += ' -F_-Fp1';
    else if (props.size === "XS") rules += ' -F_-Fn1';
    else rules += ' -F_-Fx1';
    return rules;
};
const $c679c2152e03f8bf$var$slider = function anonymous(props) {
    let rules = " ";
    rules += ' gX1';
    if (props.isDisabled) rules += ' gld1';
    else rules += ' gle1';
    rules += ' Wr1';
    rules += ' _Er1';
    rules += ' Za1';
    rules += ' Fb1';
    rules += ' _qg1';
    rules += ' Yx6BKnd1';
    rules += ' Ydklsgce1';
    rules += ' Xc1';
    rules += ' _2a1';
    rules += ' _Pa1';
    rules += ' _oa1';
    rules += ' _jf1';
    rules += ' _kc1';
    rules += ' hc1';
    rules += ' mc1';
    rules += ' lc1';
    if (props.isDisabled) rules += ' iq1';
    else rules += ' in1';
    if (props.isDisabled) rules += ' ilc1';
    else rules += ' ild1';
    rules += ' oc1';
    rules += ' nc1';
    rules += ' kc1';
    rules += ' jc1';
    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: " _Ja1 _va1"
                                    })
                                }
                            ],
                            [
                                (0, $ae3Tm$TextContext),
                                {
                                    slots: {
                                        [(0, $ae3Tm$DEFAULT_SLOT)]: {}
                                    }
                                }
                            ],
                            [
                                (0, $8e847109a6ab556d$export$9afb8bc826b033ea),
                                {
                                    styles: " _Jb1 _Nc1 Pc1 _Yb1 _7c1"
                                }
                            ]
                        ],
                        children: /*#__PURE__*/ (0, $ae3Tm$jsx)("div", {
                            ref: divRef,
                            style: (0, $10ea7662e51a285b$export$56e8cba416805d8d)(divRef)({
                                isPressed: isPressed
                            }),
                            className: " sd1 Uc1 Usd1 qc1 qsd1 Yd1 Xb1 _2b1 eb1 Na1",
                            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
