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 = (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 += ' sd1';
    rules += ' qf1';
    rules += ' ea1';
    if (!width) rules += ' ZJ1';
    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';
        rules += ' plc1';
    } else {
        if (props.isPressed) rules += ' po1';
        else if (props.isFocusVisible) rules += ' po1';
        else if (props.isHovered) rules += ' po1';
        else rules += ' pt1';
        rules += ' plb1';
    }
    rules += ' Yc1';
    rules += ' Xb1';
    rules += ' _2b1';
    if (props.isInForm) {
        if (!gridColumnStart) rules += ' zhJUGr1';
    }
    rules += ' __ca1';
    return rules;
};
const $0bb99ae32af8596c$var$track = function anonymous(props) {
    let rules = " ";
    if (props.isFocusVisible) rules += ' _Lf1';
    else rules += ' _Le1';
    rules += ' Oh1';
    rules += ' Olc1';
    rules += ' _Mc1';
    rules += ' _Kd1';
    rules += ' og1';
    rules += ' ng1';
    rules += ' kg1';
    rules += ' jg1';
    rules += ' -ERv7Xb-ZmDIzbc1';
    if (props.size === "XL") rules += ' -LsrJQc-Fn1';
    else if (props.size === "L") rules += ' -LsrJQc-Fm1';
    else if (props.size === "S") rules += ' -LsrJQc-Fl1';
    else rules += ' -LsrJQc-Ft1';
    rules += ' ZAkyXj1';
    rules += ' Fpk5ROc1';
    rules += ' _oa1';
    rules += ' _kc1';
    rules += ' hc1';
    rules += ' mc1';
    rules += ' lc1';
    rules += ' _jf1';
    rules += ' Yd1';
    rules += ' Xb1';
    rules += ' _2b1';
    rules += ' _yb1';
    if (props.isSelected) rules += ' iA1';
    else if (props.isDisabled) {
        rules += ' io1';
        rules += ' ilc1';
    } else {
        if (props.isPressed) rules += ' in1';
        else if (props.isFocusVisible) rules += ' in1';
        else if (props.isHovered) rules += ' in1';
        else rules += ' iv1';
        rules += ' ila1';
    }
    if (props.isSelected) {
        if (props.isDisabled) {
            rules += ' gw1';
            rules += ' gld1';
        } else {
            if (props.isEmphasized) {
                if (props.isPressed) rules += ' gY1';
                else if (props.isFocusVisible) rules += ' gY1';
                else if (props.isHovered) rules += ' gY1';
                else rules += ' g31';
            } else {
                if (props.isPressed) rules += ' gu1';
                else if (props.isFocusVisible) rules += ' gu1';
                else if (props.isHovered) rules += ' gu1';
                else rules += ' g01';
            }
            rules += ' gle1';
        }
    } else rules += ' gX1';
    return rules;
};
const $0bb99ae32af8596c$var$handle = function anonymous(props) {
    let rules = " ";
    rules += ' Fb1';
    rules += ' fa1';
    rules += ' og1';
    rules += ' ng1';
    rules += ' kg1';
    rules += ' jg1';
    if (props.isSelected) rules += ' gX1';
    else if (props.isDisabled) {
        rules += ' gw1';
        rules += ' gld1';
    } else {
        if (props.isPressed) rules += ' gu1';
        else if (props.isFocusVisible) rules += ' gu1';
        else if (props.isHovered) rules += ' gu1';
        else rules += ' g01';
    }
    rules += ' Yd1';
    rules += ' Xb1';
    rules += ' _2b1';
    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
