"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __objRest = (source, exclude) => {
  var target = {};
  for (var prop in source)
    if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
      target[prop] = source[prop];
  if (source != null && __getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(source)) {
      if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
        target[prop] = source[prop];
    }
  return target;
};
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 Checkbox_exports = {};
__export(Checkbox_exports, {
  default: () => Checkbox_default
});
module.exports = __toCommonJS(Checkbox_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_react = __toESM(require("react"));
var import_prop_types = require("prop-types");
var import_styled_components = __toESM(require("styled-components"));
var import_react_native = require("react-native");
var import_yoga_common = require("@gympass/yoga-common");
var import_yoga_icons = require("@gympass/yoga-icons");
var import_Text = __toESM(require("../../Text"));
const CheckboxWrapper = import_styled_components.default.View`
  flex-direction: row;
  align-items: center;
`;
const Label = (0, import_styled_components.default)(import_Text.default.Regular)(
  ({
    theme: {
      yoga: {
        components: { checkbox }
      }
    }
  }) => `
  padding-left: ${checkbox.label.padding.left}px;

  font-size: ${checkbox.label.font.size}px;

  color: ${checkbox.label.font.color};
`
);
const HelperWrapper = import_styled_components.default.View(
  ({
    theme: {
      yoga: {
        components: { checkbox }
      }
    }
  }) => `
  margin-top: ${checkbox.helper.margin.top}px;
`
);
const Helper = (0, import_styled_components.default)(import_Text.default.Regular)(
  ({
    error,
    theme: {
      yoga: {
        colors: { feedback },
        components: { checkbox }
      }
    }
  }) => `
  font-size: ${checkbox.helper.font.size}px;

  color: ${error ? feedback.attention[1] : checkbox.helper.font.color};
`
);
const CheckBackground = import_styled_components.default.View(
  ({
    checked,
    disabled,
    inverted,
    error,
    theme: {
      yoga: {
        colors: { primary, feedback, white },
        components: { checkbox }
      }
    }
  }) => {
    let borderColor = checkbox.border.color;
    let bgColor = "transparent";
    if (error) {
      [, borderColor] = feedback.attention;
      if (checked) {
        [, bgColor] = feedback.attention;
      }
    } else if (disabled) {
      borderColor = checkbox.disabled.border.color;
      if (checked) {
        bgColor = checkbox.disabled.backgroundColor;
      }
    } else if (checked) {
      borderColor = primary;
      bgColor = primary;
      if (inverted) {
        bgColor = white;
        borderColor = white;
      }
    } else if (inverted) {
      borderColor = white;
    }
    return `
      position: absolute;

      width: ${checkbox.size}px;
      height: ${checkbox.size}px;

      border-radius: ${checkbox.border.radius}px;
      border-width: ${checkbox.border.width}px;
      border-style: solid;

      background-color: ${bgColor};

      border-color: ${borderColor};
    `;
  }
);
const Shadow = import_styled_components.default.View(
  ({
    checked,
    inverted,
    theme: {
      yoga: {
        colors: { primary, elements, white },
        components: { checkbox }
      }
    }
  }) => {
    const size = checkbox.size * 1.67;
    const shadowColor = checked ? primary : elements.backgroundAndDisabled;
    return `
      width: ${size}px;
      height: ${size}px;

      background-color: ${(0, import_yoga_common.hexToRgb)(inverted ? white : shadowColor, 0.75)};
      border-radius: ${checkbox.hover.border.radius}px;
    `;
  }
);
const CheckArea = import_styled_components.default.View(
  ({
    theme: {
      yoga: {
        components: { checkbox }
      }
    }
  }) => `
  justify-content: center;
  align-items: center;

  width: ${checkbox.size}px;
  height: ${checkbox.size}px;
`
);
const Checkbox = (_a) => {
  var _b = _a, {
    label = void 0,
    helper = void 0,
    disabled = false,
    checked = false,
    error = void 0,
    style = {},
    onPressIn = () => {
    },
    onPressOut = () => {
    },
    inverted = false,
    theme: {
      yoga: {
        components: { checkbox },
        colors
      }
    }
  } = _b, rest = __objRest(_b, [
    "label",
    "helper",
    "disabled",
    "checked",
    "error",
    "style",
    "onPressIn",
    "onPressOut",
    "inverted",
    "theme"
  ]);
  const [pressed, setPressed] = (0, import_react.useState)(false);
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native.View, { children: [
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      import_react_native.TouchableWithoutFeedback,
      __spreadProps(__spreadValues({}, rest), {
        disabled,
        onPressIn: (e) => {
          setPressed(true);
          onPressIn(e);
        },
        onPressOut: (e) => {
          setPressed(false);
          onPressOut(e);
        },
        children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(CheckboxWrapper, { style, children: [
          /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(CheckArea, { children: [
            pressed && !disabled && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Shadow, { pressed, checked, inverted }),
            /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
              CheckBackground,
              __spreadValues({}, {
                disabled,
                checked,
                error,
                pressed,
                inverted
              })
            ),
            checked && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
              import_yoga_icons.Check,
              {
                fill: inverted ? colors.primary : checkbox.checked.icon.color,
                style: { position: "absolute" },
                width: 24,
                height: 24
              }
            )
          ] }),
          label && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Label, { children: label })
        ] })
      })
    ),
    (helper || error) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(HelperWrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Helper, { error, children: error || helper }) })
  ] });
};
Checkbox.propTypes = {
  label: import_prop_types.string,
  /** set a short helper text under checkbox */
  helper: import_prop_types.string,
  checked: import_prop_types.bool,
  disabled: import_prop_types.bool,
  inverted: import_prop_types.bool,
  error: import_prop_types.string,
  style: (0, import_prop_types.shape)({}),
  onPressIn: import_prop_types.func,
  onPressOut: import_prop_types.func
};
Checkbox.displayName = "Checkbox";
var Checkbox_default = (0, import_styled_components.withTheme)(Checkbox);
