require("./Switch.css");
var $e991cbcdf82ced71$exports = require("./CenterBaseline.cjs");
var $bfa4962d90c8af48$exports = require("./Form.cjs");
var $2061c83559b50a66$exports = require("./pressScale.cjs");
var $ac757a4c2bd72aee$exports = require("../icons/useSpectrumContextProps.cjs");
var $bxoLC$reactjsxruntime = require("react/jsx-runtime");
var $bxoLC$reactariacomponents = require("react-aria-components");
var $bxoLC$react = require("react");
var $bxoLC$reactspectrumutils = require("@react-spectrum/utils");


function $parcel$export(e, n, v, s) {
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
}

$parcel$export(module.exports, "SwitchContext", () => $0bb99ae32af8596c$export$8699e3b644d5a28a);
$parcel$export(module.exports, "Switch", () => $0bb99ae32af8596c$export$b5d5cf8927ab7262);
/*
 * 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 $0bb99ae32af8596c$export$8699e3b644d5a28a = /*#__PURE__*/ (0, $bxoLC$react.createContext)(null);
const $0bb99ae32af8596c$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 += ' sd11';
    rules += ' qf11';
    rules += ' ea11';
    if (!width) rules += ' ZJ11';
    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';
        rules += ' plc11';
    } else {
        if (props.isPressed) rules += ' po11';
        else if (props.isFocusVisible) rules += ' po11';
        else if (props.isHovered) rules += ' po11';
        else rules += ' pt11';
        rules += ' plb11';
    }
    rules += ' Yc11';
    rules += ' Xb11';
    rules += ' _2b11';
    if (props.isInForm) {
        if (!gridColumnStart) rules += ' zhJUGr11';
    }
    rules += ' __ca11';
    return rules;
};
const $0bb99ae32af8596c$var$track = function anonymous(props) {
    let rules = " ";
    if (props.isFocusVisible) rules += ' _Lf11';
    else rules += ' _Le11';
    rules += ' Oh11';
    rules += ' Olc11';
    rules += ' _Mc11';
    rules += ' _Kd11';
    rules += ' og11';
    rules += ' ng11';
    rules += ' kg11';
    rules += ' jg11';
    rules += ' -ERv7Xb-ZmDIzbc11';
    if (props.size === "XL") rules += ' -LsrJQc-Fn11';
    else if (props.size === "L") rules += ' -LsrJQc-Fm11';
    else if (props.size === "S") rules += ' -LsrJQc-Fl11';
    else rules += ' -LsrJQc-Ft11';
    rules += ' ZAkyXj11';
    rules += ' Fpk5ROc11';
    rules += ' _oa11';
    rules += ' _kc11';
    rules += ' hc11';
    rules += ' mc11';
    rules += ' lc11';
    rules += ' _jf11';
    rules += ' Yd11';
    rules += ' Xb11';
    rules += ' _2b11';
    rules += ' _yb11';
    if (props.isSelected) rules += ' iA11';
    else if (props.isDisabled) {
        rules += ' io11';
        rules += ' ilc11';
    } else {
        if (props.isPressed) rules += ' in11';
        else if (props.isFocusVisible) rules += ' in11';
        else if (props.isHovered) rules += ' in11';
        else rules += ' iv11';
        rules += ' ila11';
    }
    if (props.isSelected) {
        if (props.isDisabled) {
            rules += ' gw11';
            rules += ' gld11';
        } else {
            if (props.isEmphasized) {
                if (props.isPressed) rules += ' gY11';
                else if (props.isFocusVisible) rules += ' gY11';
                else if (props.isHovered) rules += ' gY11';
                else rules += ' g311';
            } else {
                if (props.isPressed) rules += ' gu11';
                else if (props.isFocusVisible) rules += ' gu11';
                else if (props.isHovered) rules += ' gu11';
                else rules += ' g011';
            }
            rules += ' gle11';
        }
    } else rules += ' gX11';
    return rules;
};
const $0bb99ae32af8596c$var$handle = function anonymous(props) {
    let rules = " ";
    rules += ' Fb11';
    rules += ' fa11';
    rules += ' og11';
    rules += ' ng11';
    rules += ' kg11';
    rules += ' jg11';
    if (props.isSelected) rules += ' gX11';
    else if (props.isDisabled) {
        rules += ' gw11';
        rules += ' gld11';
    } else {
        if (props.isPressed) rules += ' gu11';
        else if (props.isFocusVisible) rules += ' gu11';
        else if (props.isHovered) rules += ' gu11';
        else rules += ' g011';
    }
    rules += ' Yd11';
    rules += ' Xb11';
    rules += ' _2b11';
    return rules;
};
// Use an inline style to calculate the transform so we can combine it with the press scale.
const $0bb99ae32af8596c$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 $0bb99ae32af8596c$export$b5d5cf8927ab7262 = /*#__PURE__*/ (0, $bxoLC$react.forwardRef)(function Switch(props, ref) {
    [props, ref] = (0, $ac757a4c2bd72aee$exports.useSpectrumContextProps)(props, ref, $0bb99ae32af8596c$export$8699e3b644d5a28a);
    let { children: children, UNSAFE_className: UNSAFE_className = '', UNSAFE_style: UNSAFE_style } = props;
    let inputRef = (0, $bxoLC$react.useRef)(null);
    let domRef = (0, $bxoLC$reactspectrumutils.useFocusableRef)(ref, inputRef);
    let handleRef = (0, $bxoLC$react.useRef)(null);
    let isInForm = !!(0, $bxoLC$react.useContext)((0, $bfa4962d90c8af48$exports.FormContext));
    let { direction: direction } = (0, $bxoLC$reactariacomponents.useLocale)();
    props = (0, $bfa4962d90c8af48$exports.useFormProps)(props);
    return /*#__PURE__*/ (0, $bxoLC$reactjsxruntime.jsx)((0, $bxoLC$reactariacomponents.Switch), {
        ...props,
        ref: domRef,
        inputRef: inputRef,
        style: UNSAFE_style,
        className: (renderProps)=>UNSAFE_className + $0bb99ae32af8596c$var$wrapper({
                ...renderProps,
                isInForm: isInForm,
                size: props.size || 'M'
            }, props.styles),
        children: (renderProps)=>/*#__PURE__*/ (0, $bxoLC$reactjsxruntime.jsxs)((0, $bxoLC$reactjsxruntime.Fragment), {
                children: [
                    /*#__PURE__*/ (0, $bxoLC$reactjsxruntime.jsx)((0, $e991cbcdf82ced71$exports.CenterBaseline), {
                        children: /*#__PURE__*/ (0, $bxoLC$reactjsxruntime.jsx)("div", {
                            className: $0bb99ae32af8596c$var$track({
                                ...renderProps,
                                size: props.size || 'M',
                                isEmphasized: props.isEmphasized
                            }),
                            children: /*#__PURE__*/ (0, $bxoLC$reactjsxruntime.jsx)("div", {
                                ref: handleRef,
                                style: (0, $2061c83559b50a66$exports.pressScale)(handleRef, $0bb99ae32af8596c$var$transformStyle)({
                                    ...renderProps,
                                    direction: direction
                                }),
                                className: $0bb99ae32af8596c$var$handle(renderProps)
                            })
                        })
                    }),
                    children
                ]
            })
    });
});


//# sourceMappingURL=Switch.cjs.map
