function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
import { createContext, useContext } from 'react';
import { TouchableOpacity, View } from 'react-native';
import { Typography } from '../Typography/Typography';
import { useStyles } from './styles';
import { capitalize } from '../../../social/utils';
import { SvgXml } from 'react-native-svg';
const defaultTabContext = {
  variant: 'chip',
  activeTab: '',
  onChangeTab: () => {}
};
const TabContext = /*#__PURE__*/createContext(defaultTabContext);
function useTabContext() {
  return useContext(TabContext);
}
function Tabs({
  variant = 'chip',
  activeTab,
  onChangeTab,
  children
}) {
  return /*#__PURE__*/React.createElement(TabContext.Provider, {
    value: {
      variant,
      activeTab,
      onChangeTab
    }
  }, children);
}
function TabList({
  children,
  style,
  ...props
}) {
  const {
    styles: baseStyles
  } = useStyles();
  const styles = baseStyles;
  const {
    variant
  } = useTabContext();
  return /*#__PURE__*/React.createElement(View, _extends({}, props, {
    style: [styles[`${variant}TabList`], style]
  }), children);
}
function Tab({
  value,
  children,
  type = 'title',
  iconProps,
  ...props
}) {
  const {
    styles: baseStyles
  } = useStyles();
  const styles = baseStyles;
  const {
    activeTab,
    onChangeTab,
    variant
  } = useTabContext();
  const isActive = activeTab === value;
  const Label = type === 'body' ? Typography.BodyBold : Typography.TitleBold;
  return /*#__PURE__*/React.createElement(TouchableOpacity, _extends({
    activeOpacity: 0.7,
    onPress: () => onChangeTab(value),
    style: [styles[`${variant}Tab`], isActive && [styles[`active${capitalize(variant)}Tab`]]]
  }, props), variant === 'icon' ? /*#__PURE__*/React.createElement(SvgXml, {
    width: (iconProps === null || iconProps === void 0 ? void 0 : iconProps.width) || 24,
    height: (iconProps === null || iconProps === void 0 ? void 0 : iconProps.height) || 24,
    xml: (iconProps === null || iconProps === void 0 ? void 0 : iconProps.xml) ?? '',
    color: isActive ? styles[`active${capitalize(variant)}TabText`].color : styles[`${variant}TabText`].color
  }) : /*#__PURE__*/React.createElement(Label, {
    style: [styles[`${variant}TabText`], isActive && [styles[`active${capitalize(variant)}TabText`]]]
  }, children));
}
function TabContent({
  value,
  children
}) {
  const {
    activeTab
  } = useTabContext();
  const isActive = activeTab === value;
  return isActive ? children : null;
}
Tabs.Tab = Tab;
Tabs.List = TabList;
Tabs.Content = TabContent;
export default Tabs;
//# sourceMappingURL=Tabs.js.map