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 += ' sd12';
    rules += ' Ub12';
    rules += ' qb12';
    rules += ' gH12';
    rules += ' ob12';
    rules += ' nb12';
    rules += ' kb12';
    rules += ' jb12';
    if (!width) rules += ' ZJ12';
    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 += ' _Lf12';
    else rules += ' _Le12';
    rules += ' Oh12';
    rules += ' _Mc12';
    rules += ' _Kd12';
    if (props.size === "XL") {
        rules += ' uk12';
        rules += ' uch12';
        rules += ' udi12';
        rules += ' uea12';
        rules += ' ugb12';
        rules += ' uhd12';
        rules += ' uje12';
        rules += ' u2NhKxcl12';
        rules += ' uic12';
    } else if (props.size === "L") {
        rules += ' uk12';
        rules += ' uch12';
        rules += ' udi12';
        rules += ' uea12';
        rules += ' ugb12';
        rules += ' uhd12';
        rules += ' uje12';
        rules += ' u2NhKxcl12';
        rules += ' uic12';
    } else if (props.size === "S") {
        rules += ' uk12';
        rules += ' uch12';
        rules += ' udi12';
        rules += ' uea12';
        rules += ' ugb12';
        rules += ' uhd12';
        rules += ' uje12';
        rules += ' u2NhKxcl12';
        rules += ' uic12';
    } else if (props.size === "XS") {
        rules += ' uk12';
        rules += ' uch12';
        rules += ' udi12';
        rules += ' uea12';
        rules += ' ugb12';
        rules += ' uhd12';
        rules += ' uje12';
        rules += ' u2NhKxcl12';
        rules += ' uic12';
    } else {
        rules += ' uk12';
        rules += ' uch12';
        rules += ' udi12';
        rules += ' uea12';
        rules += ' ugb12';
        rules += ' uhd12';
        rules += ' uje12';
        rules += ' u2NhKxcl12';
        rules += ' uic12';
    }
    if (props.size === "XL") {
        rules += ' -_6BNtrc-e12';
        rules += ' vx12';
    } else if (props.size === "L") {
        rules += ' -_6BNtrc-d12';
        rules += ' vx12';
    } else if (props.size === "S") {
        rules += ' -_6BNtrc-b12';
        rules += ' vx12';
    } else if (props.size === "XS") {
        rules += ' -_6BNtrc-a12';
        rules += ' vx12';
    } else {
        rules += ' -_6BNtrc-c12';
        rules += ' vx12';
    }
    if (props.size === "XL") {
        rules += ' xb12';
        rules += ' _xa12';
    } else if (props.size === "L") {
        rules += ' xb12';
        rules += ' _xa12';
    } else if (props.size === "S") {
        rules += ' xb12';
        rules += ' _xa12';
    } else if (props.size === "XS") {
        rules += ' xb12';
        rules += ' _xa12';
    } else {
        rules += ' xb12';
        rules += ' _xa12';
    }
    if (props.size === "XL") {
        rules += ' _Fd12';
        rules += ' _FezxGHba12';
        rules += ' _FnuYUweb12';
    } else if (props.size === "L") {
        rules += ' _Fd12';
        rules += ' _FezxGHba12';
        rules += ' _FnuYUweb12';
    } else if (props.size === "S") {
        rules += ' _Fd12';
        rules += ' _FezxGHba12';
        rules += ' _FnuYUweb12';
    } else if (props.size === "XS") {
        rules += ' _Fd12';
        rules += ' _FezxGHba12';
        rules += ' _FnuYUweb12';
    } else {
        rules += ' _Fd12';
        rules += ' _FezxGHba12';
        rules += ' _FnuYUweb12';
    }
    if (props.isDisabled) rules += ' pp12';
    else if (props.isSelected) {
        if (props.isPressed) rules += ' po12';
        else if (props.isFocusVisible) rules += ' po12';
        else if (props.isHovered) rules += ' po12';
        else rules += ' pt12';
    } else {
        if (props.isPressed) rules += ' pt12';
        else if (props.isFocusVisible) rules += ' pt12';
        else if (props.isHovered) rules += ' pt12';
        else rules += ' pv12';
    }
    if (props.isSelected) rules += ' ple12';
    else if (props.isDisabled) rules += ' plc12';
    else rules += ' plb12';
    rules += ' sd12';
    rules += ' eb12';
    rules += ' _oa12';
    rules += ' Sv12';
    rules += ' SgLWx3bd12';
    rules += ' Rv12';
    rules += ' RgLWx3bd12';
    if (props.size === "XL") {
        if (!minWidth) rules += ' Nl12';
    } else if (props.size === "L") {
        if (!minWidth) rules += ' Nj12';
    } else if (props.size === "S") {
        if (!minWidth) rules += ' Nf12';
    } else if (props.size === "XS") {
        if (!minWidth) rules += ' Ne12';
    } else if (!minWidth) rules += ' Nk12';
    if (props.size === "XL") rules += ' -SFnbic-_JaP8ec12';
    else if (props.size === "L") rules += ' -SFnbic-_J0K2hn12';
    else if (props.size === "S") rules += ' -SFnbic-_JJOW22b12';
    else if (props.size === "XS") rules += ' -SFnbic-_JICefdd12';
    else rules += ' -SFnbic-_Jb12';
    rules += ' -Bu7z1c-ob12';
    rules += ' oj12';
    rules += ' nj12';
    rules += ' kj12';
    rules += ' jj12';
    rules += ' qc12';
    rules += ' qsd12';
    rules += ' -Qg41Lb-IAxCW0c12';
    rules += ' -Qg41Lb-gLWx3bIy12';
    rules += ' FRuFGYc12';
    rules += ' _Ca12';
    if (!position) rules += ' _Pc12';
    rules += ' _yb12';
    if (props.isJustified) {
        if (!flexGrow) rules += ' _ub12';
    }
    if (props.isJustified) {
        if (!flexBasis) rules += ' _sb12';
    }
    if (!flexShrink) rules += ' _va12';
    rules += ' _7c12';
    rules += ' __ca12';
    rules += ' _4c12';
    rules += ' g912';
    rules += ' _je12';
    rules += ' -_8sjo0b-t5ZbAob12';
    if (props.isSelected) {
        if (!zIndex) rules += ' _9b12';
    } else if (!zIndex) rules += ' _9c12';
    if (props.size === "XL") rules += ' -F_-Fz12';
    else if (props.size === "L") rules += ' -F_-Fv12';
    else if (props.size === "S") rules += ' -F_-Fp12';
    else if (props.size === "XS") rules += ' -F_-Fn12';
    else rules += ' -F_-Fx12';
    return rules;
};
const $c679c2152e03f8bf$var$slider = function anonymous(props) {
    let rules = " ";
    rules += ' gX12';
    if (props.isDisabled) rules += ' gld12';
    else rules += ' gle12';
    rules += ' Wr12';
    rules += ' _Er12';
    rules += ' Za12';
    rules += ' Fb12';
    rules += ' _qg12';
    rules += ' Yx6BKnd12';
    rules += ' Ydklsgce12';
    rules += ' Xc12';
    rules += ' _2a12';
    rules += ' _Pa12';
    rules += ' _oa12';
    rules += ' _jf12';
    rules += ' _kc12';
    rules += ' hc12';
    rules += ' mc12';
    rules += ' lc12';
    if (props.isDisabled) rules += ' iq12';
    else rules += ' in12';
    if (props.isDisabled) rules += ' ilc12';
    else rules += ' ild12';
    rules += ' oc12';
    rules += ' nc12';
    rules += ' kc12';
    rules += ' jc12';
    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: " _Ja12 _va12"
                                    })
                                }
                            ],
                            [
                                (0, $ae3Tm$TextContext),
                                {
                                    slots: {
                                        [(0, $ae3Tm$DEFAULT_SLOT)]: {}
                                    }
                                }
                            ],
                            [
                                (0, $8e847109a6ab556d$export$9afb8bc826b033ea),
                                {
                                    styles: " _Jb12 _Nc12 Pc12 _Yb12 _7c12"
                                }
                            ]
                        ],
                        children: /*#__PURE__*/ (0, $ae3Tm$jsx)("div", {
                            ref: divRef,
                            style: (0, $10ea7662e51a285b$export$56e8cba416805d8d)(divRef)({
                                isPressed: isPressed
                            }),
                            className: " sd12 Uc12 Usd12 qc12 qsd12 Yd12 Xb12 _2b12 eb12 Na12",
                            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
