import "./Switch.css";
import {CenterBaseline as $1f4b04be3f24aae3$export$768dac55bb57081d} from "./CenterBaseline.mjs";
import {FormContext as $9b916426527cebe7$export$c24727297075ec6a, useFormProps as $9b916426527cebe7$export$a6b5be5c6b451665} from "./Form.mjs";
import {pressScale as $10ea7662e51a285b$export$56e8cba416805d8d} from "./pressScale.mjs";
import {useFocusableRef as $80ecb974df713a30$export$96a734597687c040} from "./useDOMRef.mjs";
import {useSpectrumContextProps as $5ce63c423902f47d$export$764f6146fadd77f7} from "../../icons/useSpectrumContextProps.mjs";
import {jsx as $8aRsI$jsx, jsxs as $8aRsI$jsxs, Fragment as $8aRsI$Fragment} from "react/jsx-runtime";
import {Switch as $8aRsI$Switch} from "react-aria-components/Switch";
import {createContext as $8aRsI$createContext, forwardRef as $8aRsI$forwardRef, useRef as $8aRsI$useRef, useContext as $8aRsI$useContext} from "react";
import {useLocale as $8aRsI$useLocale} from "react-aria/I18nProvider";

/*
 * 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 $8926b17b75ae985d$export$8699e3b644d5a28a = /*#__PURE__*/ (0, $8aRsI$createContext)(null);
const $8926b17b75ae985d$var$wrapper = function anonymous(props, overrides) {
    let rules = " ";
    let width = false;
    let gridColumnStart = 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;
        if (p[1] === "z") gridColumnStart = true;
        rules += p[0];
    }
    rules += ' sd12';
    rules += ' qf12';
    rules += ' ea12';
    if (!width) rules += ' ZJ12';
    if (props.size === "XL") {
        rules += ' uk12';
        rules += ' ucJ9TBTb12';
        rules += ' ud3Euai12';
        rules += ' uea12';
        rules += ' ugb12';
        rules += ' uhd12';
        rules += ' uje12';
        rules += ' u2NhKxcl12';
        rules += ' uic12';
    } else if (props.size === "L") {
        rules += ' uk12';
        rules += ' ucJ9TBTb12';
        rules += ' ud3Euai12';
        rules += ' uea12';
        rules += ' ugb12';
        rules += ' uhd12';
        rules += ' uje12';
        rules += ' u2NhKxcl12';
        rules += ' uic12';
    } else if (props.size === "S") {
        rules += ' uk12';
        rules += ' ucJ9TBTb12';
        rules += ' ud3Euai12';
        rules += ' uea12';
        rules += ' ugb12';
        rules += ' uhd12';
        rules += ' uje12';
        rules += ' u2NhKxcl12';
        rules += ' uic12';
    } else if (props.size === "XS") {
        rules += ' uk12';
        rules += ' ucJ9TBTb12';
        rules += ' ud3Euai12';
        rules += ' uea12';
        rules += ' ugb12';
        rules += ' uhd12';
        rules += ' uje12';
        rules += ' u2NhKxcl12';
        rules += ' uic12';
    } else {
        rules += ' uk12';
        rules += ' ucJ9TBTb12';
        rules += ' ud3Euai12';
        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 += ' _FnuYUweb12';
    } else if (props.size === "L") {
        rules += ' _Fd12';
        rules += ' _FnuYUweb12';
    } else if (props.size === "S") {
        rules += ' _Fd12';
        rules += ' _FnuYUweb12';
    } else if (props.size === "XS") {
        rules += ' _Fd12';
        rules += ' _FnuYUweb12';
    } else {
        rules += ' _Fd12';
        rules += ' _FnuYUweb12';
    }
    if (props.isDisabled) {
        rules += ' pp12';
        rules += ' plc12';
    } else {
        if (props.isPressed) rules += ' po12';
        else if (props.isFocusVisible) rules += ' po12';
        else if (props.isHovered) rules += ' po12';
        else rules += ' pt12';
        rules += ' plb12';
    }
    rules += ' Yc12';
    rules += ' Xb12';
    rules += ' _2b12';
    if (props.isInForm) {
        if (!gridColumnStart) rules += ' zhJUGr12';
    }
    rules += ' __ca12';
    return rules;
};
const $8926b17b75ae985d$var$track = function anonymous(props) {
    let rules = " ";
    if (props.isFocusVisible) rules += ' _Lf12';
    else rules += ' _Le12';
    rules += ' Oh12';
    rules += ' Olc12';
    rules += ' _Mc12';
    rules += ' _Kd12';
    rules += ' og12';
    rules += ' ng12';
    rules += ' kg12';
    rules += ' jg12';
    rules += ' -ERv7Xb-ZmDIzbc12';
    if (props.size === "XL") rules += ' -LsrJQc-Fn12';
    else if (props.size === "L") rules += ' -LsrJQc-Fm12';
    else if (props.size === "S") rules += ' -LsrJQc-Fl12';
    else rules += ' -LsrJQc-Ft12';
    rules += ' ZAkyXj12';
    rules += ' Fpk5ROc12';
    rules += ' _oa12';
    rules += ' _kc12';
    rules += ' hc12';
    rules += ' mc12';
    rules += ' lc12';
    rules += ' _jf12';
    rules += ' Yd12';
    rules += ' Xb12';
    rules += ' _2b12';
    rules += ' _yb12';
    if (props.isSelected) rules += ' iA12';
    else if (props.isDisabled) {
        rules += ' io12';
        rules += ' ilc12';
    } else {
        if (props.isPressed) rules += ' in12';
        else if (props.isFocusVisible) rules += ' in12';
        else if (props.isHovered) rules += ' in12';
        else rules += ' iv12';
        rules += ' ila12';
    }
    if (props.isSelected) {
        if (props.isDisabled) {
            rules += ' gw12';
            rules += ' gld12';
        } else {
            if (props.isEmphasized) {
                if (props.isPressed) rules += ' gY12';
                else if (props.isFocusVisible) rules += ' gY12';
                else if (props.isHovered) rules += ' gY12';
                else rules += ' g312';
            } else {
                if (props.isPressed) rules += ' gu12';
                else if (props.isFocusVisible) rules += ' gu12';
                else if (props.isHovered) rules += ' gu12';
                else rules += ' g012';
            }
            rules += ' gle12';
        }
    } else rules += ' gX12';
    return rules;
};
const $8926b17b75ae985d$var$handle = function anonymous(props) {
    let rules = " ";
    rules += ' Fb12';
    rules += ' fa12';
    rules += ' og12';
    rules += ' ng12';
    rules += ' kg12';
    rules += ' jg12';
    if (props.isSelected) rules += ' gX12';
    else if (props.isDisabled) {
        rules += ' gw12';
        rules += ' gld12';
    } else {
        if (props.isPressed) rules += ' gu12';
        else if (props.isFocusVisible) rules += ' gu12';
        else if (props.isHovered) rules += ' gu12';
        else rules += ' g012';
    }
    rules += ' Yd12';
    rules += ' Xb12';
    rules += ' _2b12';
    return rules;
};
// Use an inline style to calculate the transform so we can combine it with the press scale.
const $8926b17b75ae985d$var$transformStyle = ({ isSelected: isSelected, direction: direction })=>{
    // In the default state, the handle is 8px smaller than the track. When selected it grows to 6px smaller than the track.
    // Normally this could be calculated as a scale transform with (trackHeight - 8px) / trackHeight, however,
    // CSS does not allow division with units. To solve this we use a 3d perspective transform. Perspective is the
    // distance from the Z=0 plane to the viewer. Since we want to scale the handle by a fixed amount and we cannot divide
    // by a value with units, we can set the Z translation to a fixed amount and change the perspective in order to achieve
    // the desired effect. Given the following formula:
    //
    //   scale = perspective / (perspective - translateZ)
    //
    // and desired scale factors (accounting for the 2px border on each side of the track):
    //
    //   defaultScale = (trackHeight - 8px) / (trackHeight - 4px)
    //   selectedScale = (trackHeight - 6px) / (trackHeight - 4px)
    //
    // we can solve for the perspective needed in each case where translateZ is hard coded to -4px:
    //
    //    defaultPerspective = trackHeight - 8px
    //    selectedPerspective = 2 * (trackHeight - 6px)
    const placement = direction === 'ltr' ? 'translateX(calc(var(--trackWidth) - 100% - 4px)) perspective(calc(2 * (var(--trackHeight) - 6px))) translateZ(-4px)' : 'translateX(calc(100% - var(--trackWidth) + 4px)) perspective(calc(2 * (var(--trackHeight) - 6px))) translateZ(-4px)';
    return {
        transform: isSelected ? placement : 'perspective(calc(var(--trackHeight) - 8px)) translateZ(-4px)'
    };
};
const $8926b17b75ae985d$export$b5d5cf8927ab7262 = /*#__PURE__*/ (0, $8aRsI$forwardRef)(function Switch(props, ref) {
    [props, ref] = (0, $5ce63c423902f47d$export$764f6146fadd77f7)(props, ref, $8926b17b75ae985d$export$8699e3b644d5a28a);
    let { children: children, UNSAFE_className: UNSAFE_className = '', UNSAFE_style: UNSAFE_style } = props;
    let inputRef = (0, $8aRsI$useRef)(null);
    let domRef = (0, $80ecb974df713a30$export$96a734597687c040)(ref, inputRef);
    let handleRef = (0, $8aRsI$useRef)(null);
    let isInForm = !!(0, $8aRsI$useContext)((0, $9b916426527cebe7$export$c24727297075ec6a));
    let { direction: direction } = (0, $8aRsI$useLocale)();
    props = (0, $9b916426527cebe7$export$a6b5be5c6b451665)(props);
    return /*#__PURE__*/ (0, $8aRsI$jsx)((0, $8aRsI$Switch), {
        ...props,
        ref: domRef,
        inputRef: inputRef,
        style: UNSAFE_style,
        className: (renderProps)=>UNSAFE_className + $8926b17b75ae985d$var$wrapper({
                ...renderProps,
                isInForm: isInForm,
                size: props.size || 'M'
            }, props.styles),
        children: (renderProps)=>/*#__PURE__*/ (0, $8aRsI$jsxs)((0, $8aRsI$Fragment), {
                children: [
                    /*#__PURE__*/ (0, $8aRsI$jsx)((0, $1f4b04be3f24aae3$export$768dac55bb57081d), {
                        children: /*#__PURE__*/ (0, $8aRsI$jsx)("div", {
                            className: $8926b17b75ae985d$var$track({
                                ...renderProps,
                                size: props.size || 'M',
                                isEmphasized: props.isEmphasized
                            }),
                            children: /*#__PURE__*/ (0, $8aRsI$jsx)("div", {
                                ref: handleRef,
                                style: (0, $10ea7662e51a285b$export$56e8cba416805d8d)(handleRef, $8926b17b75ae985d$var$transformStyle)({
                                    ...renderProps,
                                    direction: direction
                                }),
                                className: $8926b17b75ae985d$var$handle(renderProps)
                            })
                        })
                    }),
                    children
                ]
            })
    });
});


export {$8926b17b75ae985d$export$8699e3b644d5a28a as SwitchContext, $8926b17b75ae985d$export$b5d5cf8927ab7262 as Switch};
//# sourceMappingURL=Switch.mjs.map
