"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var Switch_exports = {};
__export(Switch_exports, {
  default: () => Switch_default
});
module.exports = __toCommonJS(Switch_exports);
var import_react = __toESM(require("react"));
var import_styled_components = __toESM(require("styled-components"));
var import_Text = __toESM(require("../../asorted/Text"));
var import_Flex = __toESM(require("../../layout/Flex"));
const Container = (0, import_styled_components.default)(import_Flex.default).attrs({ alignItems: "center", flexDirection: "row" })`
  width: fit-content;
  column-gap: ${(p) => p.theme.space[5]}px;
  cursor: pointer;

  /* reversed VARIANT */
  &[data-reversed="true"] {
    flex-direction: row-reverse;
  }

  &[data-disabled="true"] {
    cursor: unset;
  }
`;
const Input = import_styled_components.default.input`
  position: absolute;
  visibility: hidden;
`;
const Label = (0, import_styled_components.default)(import_Text.default)`
  &:first-letter {
    text-transform: uppercase;
  }
`;
const Switcher = import_styled_components.default.div`
  --ll-switch-width: ${(p) => p.theme.space[14]}px;
  --ll-switch-height: ${(p) => p.theme.space[9]}px;
  --ll-switch-padding: ${(p) => p.theme.space[2]}px;

  position: relative;
  display: inline-block;

  background: ${(props) => props.theme.colors.neutral.c60};
  border-radius: ${(p) => p.theme.space[6]}px;
  width: var(--ll-switch-width);
  height: var(--ll-switch-height);

  transition: background 200ms;

  &:before,
  &:after {
    content: "";
  }

  &:focus {
    outline-style: auto;
    outline: 1px solid ${(props) => props.theme.colors.neutral.c90};
    outline-offset: ${(p) => p.theme.space[1]}px;
  }

  /* CIRCLE ELEMENT */
  &:before {
    position: absolute;
    display: block;
    background: ${(props) => props.theme.colors.constant.white};
    border-radius: ${(p) => p.theme.space[12]}px;

    width: calc(calc(var(--ll-switch-width) / 2) - var(--ll-switch-padding));
    height: calc(calc(var(--ll-switch-width) / 2) - var(--ll-switch-padding));
    top: var(--ll-switch-padding);
    transform: translateX(var(--ll-switch-padding));
    transition: transform 0.25s;
  }

  /* SMALL VARIANT */
  &[data-size="small"] {
    --ll-switch-width: ${(p) => p.theme.space[8]}px;
    --ll-switch-height: ${(p) => p.theme.space[6]}px;
  }

  &:hover {
    background-color: ${(props) => props.theme.colors.neutral.c70};
  }

  &:active {
    background-color: ${(props) => props.theme.colors.neutral.c80};
  }

  /* CHECKED VARIANT */
  ${Input}:checked ~ & {
    background: ${(props) => props.theme.colors.primary.c80};

    &:before {
      transform: translateX(calc(var(--ll-switch-width) / 2));
    }

    &:hover {
      background: ${(props) => props.theme.colors.primary.c90};
    }

    :active {
      background: ${(props) => props.theme.colors.primary.c100};
    }
  }
`;
const Switch = ({
  name,
  checked,
  onChange,
  label,
  disabled,
  reversed,
  size
}) => {
  const handleFocusKeyDown = (e) => {
    if (e.key.match(/enter/i))
      onChange(e);
  };
  const handleClick = (e) => {
    if (!disabled)
      onChange(e);
  };
  return /* @__PURE__ */ import_react.default.createElement(
    Container,
    {
      role: "button",
      "data-reversed": reversed,
      "data-disabled": disabled,
      onClick: handleClick,
      tabIndex: 0,
      "aria-pressed": checked,
      onKeyDown: handleFocusKeyDown
    },
    /* @__PURE__ */ import_react.default.createElement(Input, { type: "checkbox", name, id: name, disabled, checked }),
    /* @__PURE__ */ import_react.default.createElement(Switcher, { "data-size": size }),
    label ? /* @__PURE__ */ import_react.default.createElement(Label, { variant: "paragraph" }, label) : null
  );
};
var Switch_default = Switch;
//# sourceMappingURL=Switch.js.map
