var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
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;
};
import { jsx, jsxs } from "react/jsx-runtime";
import React from "react";
import { number, arrayOf, bool, func, node } from "prop-types";
import styled, { css, withTheme } from "styled-components";
import { TouchableWithoutFeedback } from "react-native";
import { hexToRgb } from "@gympass/yoga-common";
import Counter from "./Counter";
import { theme } from "../../Theme";
import Text from "../../Text";
import Icon from "../../Icon";
const BORDER_OPACITY = 0.4;
const Wrapper = styled.View.attrs(({ theme: { yoga } }) => {
  return {
    borderColor: hexToRgb(yoga.colors.secondary, BORDER_OPACITY)
  };
})`
  height: 32px;
  max-width: 216px;

  flex-direction: row;
  align-items: center;
  justify-content: flex-start;

  margin-right: ${theme.spacing.xxsmall}px;
  padding: ${theme.spacing.xxxsmall}px ${theme.spacing.xsmall}px;

  border-style: solid;
  border-radius: ${theme.radii.circle}px;
  border-width: ${theme.borders.small}px;

  background-color: ${theme.colors.white};

  overflow: hidden;

  ${({ disabled }) => disabled ? css`
          background-color: ${theme.colors.elements.backgroundAndDisabled};
          border-color: ${theme.colors.elements.backgroundAndDisabled};
        ` : ""}

  ${({ selected }) => selected ? css`
          background-color: ${theme.colors.secondary};
        ` : ""}

  ${({ justAnIcon }) => justAnIcon ? css`
          padding: ${theme.spacing.xxsmall}px;
        ` : ""}
`;
const StyledChips = styled(Text)`
  flex-shrink: 1;
  ${({ disabled }) => disabled ? css`
          color: ${theme.colors.text.disabled};
        ` : ""}

  ${({ selected }) => selected ? css`
          color: ${theme.colors.white};
        ` : ""}
`;
const Chips = React.forwardRef(
  (_a, ref) => {
    var _b = _a, {
      children = void 0,
      selected = false,
      counter = void 0,
      icons = [],
      disabled = false,
      onToggle = void 0,
      onPress = onToggle,
      theme: {
        yoga: { spacing, colors }
      }
    } = _b, props = __objRest(_b, [
      "children",
      "selected",
      "counter",
      "icons",
      "disabled",
      "onToggle",
      "onPress",
      "theme"
    ]);
    const [FirstIcon, SecondIcon] = icons;
    const justAnIcon = (icons[0] || icons[1]) && !children;
    const fillSelected = selected ? "white" : "secondary";
    const fillIcon = disabled ? colors.text.disabled : fillSelected;
    return /* @__PURE__ */ jsx(
      TouchableWithoutFeedback,
      __spreadProps(__spreadValues({
        onPress,
        ref,
        accessibilityRole: "button"
      }, props), {
        children: /* @__PURE__ */ jsxs(
          Wrapper,
          {
            disabled,
            selected,
            justAnIcon,
            children: [
              SecondIcon && /* @__PURE__ */ jsx(
                Icon,
                {
                  as: SecondIcon,
                  fill: fillIcon,
                  width: "small",
                  height: "small",
                  style: {
                    marginRight: children ? spacing.xxxsmall : void 0
                  }
                }
              ),
              /* @__PURE__ */ jsx(
                StyledChips,
                {
                  disabled,
                  as: selected || disabled ? Text.Overline : Text.Caption,
                  selected,
                  numberOfLines: 1,
                  children
                }
              ),
              selected && counter && !disabled && /* @__PURE__ */ jsx(Counter, { value: counter }),
              FirstIcon && /* @__PURE__ */ jsx(
                Icon,
                {
                  as: FirstIcon,
                  fill: fillIcon,
                  width: "small",
                  height: "small",
                  style: {
                    marginLeft: children ? spacing.xxxsmall : void 0
                  }
                }
              )
            ]
          }
        )
      })
    );
  }
);
Chips.propTypes = {
  /** text to be displayed */
  children: node,
  /** if the chip is selected */
  selected: bool,
  /** will display a three digit number, if the value is greater than 999 a plus
   * sign will be displayed instead. ex: "+999" */
  counter: number,
  /** disable chip */
  disabled: bool,
  /** a list of max two icons from @gympass/yoga-icons package */
  icons: arrayOf(func),
  /** onPress event */
  onToggle: func,
  onPress: func
};
var Chips_default = withTheme(Chips);
export {
  Chips_default as default
};
