"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 TabSelector_exports = {};
__export(TabSelector_exports, {
  default: () => TabSelector
});
module.exports = __toCommonJS(TabSelector_exports);
var import_react = __toESM(require("react"));
var import_styled_components = __toESM(require("styled-components"));
var import_Flex = __toESM(require("../../layout/Flex"));
var import_Text = __toESM(require("../../asorted/Text"));
var import_framer_motion = require("framer-motion");
const StyledButton = (0, import_styled_components.default)(import_Flex.default)`
  cursor: pointer;
  justify-content: center;
  align-items: center;
`;
const StyledFlex = (0, import_styled_components.default)(import_Flex.default)`
  height: 100%;
  justify-content: center;
  align-items: center;
`;
const StyledText = (0, import_styled_components.default)(import_Text.default)`
  line-height: 14.52px;
  overflow: visible;
  text-align: center;
  font-size: 12px;
  color: ${(p) => p.isSelected ? p.theme.colors.constant.black : p.theme.colors.opacityDefault.c50};
  z-index: 10;
`;
const OptionButton = ({
  option,
  selectedOption,
  handleSelectOption,
  label,
  width
}) => {
  const isSelected = selectedOption === option;
  return /* @__PURE__ */ import_react.default.createElement(StyledButton, { width, onClick: () => handleSelectOption(option) }, /* @__PURE__ */ import_react.default.createElement(StyledFlex, { isSelected }, /* @__PURE__ */ import_react.default.createElement(StyledText, { fontWeight: "semiBold", isSelected }, label)));
};
function TabSelector({
  options,
  selectedOption,
  handleSelectOption,
  labels
}) {
  const { colors } = (0, import_styled_components.useTheme)();
  const longuestLabel = labels[options[0]].length > labels[options[1]].length ? options[0] : options[1];
  const widthFactor = 8;
  const margin = 20;
  const width = labels[longuestLabel].length * widthFactor + margin;
  const semiWidth = width / 2;
  const controls = (0, import_framer_motion.useAnimation)();
  (0, import_react.useEffect)(() => {
    controls.start({
      x: selectedOption === options[0] ? -semiWidth : semiWidth,
      transition: { type: "spring", damping: 30, stiffness: 130 }
    });
  }, [selectedOption, controls, options, semiWidth]);
  return /* @__PURE__ */ import_react.default.createElement(
    import_Flex.default,
    {
      flexDirection: "row",
      justifyContent: "center",
      alignItems: "center",
      width: width * 2 + 4,
      height: "35px",
      borderRadius: "40px",
      bg: colors.opacityDefault.c05,
      position: "relative"
    },
    /* @__PURE__ */ import_react.default.createElement(
      import_framer_motion.motion.div,
      {
        style: {
          position: "absolute",
          width,
          height: "90%",
          backgroundColor: colors.primary.c80,
          borderRadius: 40
        },
        animate: controls
      }
    ),
    options.map((option) => /* @__PURE__ */ import_react.default.createElement(
      OptionButton,
      {
        width,
        key: option,
        option,
        selectedOption,
        handleSelectOption,
        label: labels[option]
      }
    ))
  );
}
//# sourceMappingURL=index.js.map
