"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.TabsBar = exports.TabPanel = exports.Tab = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _useTheme = require("../theme/use-theme.js");
var _usePressAnimation = require("../hooks/usePressAnimation.js");
var _tokens = require("../styles/tokens.js");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
const TabsContext = /*#__PURE__*/(0, _react.createContext)({
  value: '',
  onValueChange: () => {},
  variant: 'underline'
});
const TabsBarComponent = ({
  value,
  onValueChange,
  variant = 'underline',
  children,
  style,
  testID
}) => {
  const theme = (0, _useTheme.useTheme)();
  const contextValue = (0, _react.useMemo)(() => ({
    value,
    onValueChange,
    variant
  }), [value, onValueChange, variant]);
  const containerStyle = (0, _react.useMemo)(() => {
    const base = {
      flexDirection: 'row',
      alignItems: 'center'
    };
    switch (variant) {
      case 'underline':
        base.borderBottomWidth = 1;
        base.borderBottomColor = theme.colors.borderLight;
        break;
      case 'filled':
        base.backgroundColor = theme.colors.backgroundSecondary;
        base.borderRadius = _tokens.borderRadius.sm;
        base.padding = 2;
        break;
      case 'outlined':
        base.borderWidth = 1;
        base.borderColor = theme.colors.border;
        base.borderRadius = _tokens.borderRadius.sm;
        base.padding = 2;
        break;
    }
    return base;
  }, [variant, theme]);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(TabsContext.Provider, {
    value: contextValue,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.ScrollView, {
      horizontal: true,
      showsHorizontalScrollIndicator: false,
      contentContainerStyle: [containerStyle, style],
      testID: testID,
      children: children
    })
  });
};
const TabComponent = ({
  value,
  label,
  icon,
  disabled = false,
  style,
  textStyle
}) => {
  const theme = (0, _useTheme.useTheme)();
  const {
    value: selectedValue,
    onValueChange,
    variant
  } = (0, _react.useContext)(TabsContext);
  const isSelected = value === selectedValue;
  const {
    scaleAnim,
    onPressIn,
    onPressOut
  } = (0, _usePressAnimation.usePressAnimation)(0.97);
  const handlePress = (0, _react.useCallback)(() => {
    if (!disabled) {
      onValueChange(value);
    }
  }, [value, disabled, onValueChange]);
  const tabStyle = (0, _react.useMemo)(() => {
    const base = {
      flexDirection: 'row',
      alignItems: 'center',
      justifyContent: 'center',
      paddingHorizontal: _tokens.space.lg,
      paddingVertical: _tokens.space.sm,
      gap: _tokens.space.xs
    };
    switch (variant) {
      case 'underline':
        if (isSelected) {
          base.borderBottomWidth = 2;
          base.borderBottomColor = theme.colors.primary;
          base.marginBottom = -1; // overlap container border
        }
        break;
      case 'filled':
        if (isSelected) {
          base.backgroundColor = theme.colors.card;
          base.borderRadius = _tokens.borderRadius.xs + 2;
          base.shadowColor = theme.colors.shadow;
          base.shadowOffset = {
            width: 0,
            height: 1
          };
          base.shadowOpacity = 0.1;
          base.shadowRadius = 2;
          base.elevation = 1;
        }
        break;
      case 'outlined':
        if (isSelected) {
          base.backgroundColor = theme.colors.primary;
          base.borderRadius = _tokens.borderRadius.xs + 2;
        }
        break;
    }
    return base;
  }, [variant, isSelected, theme]);
  const labelStyle = (0, _react.useMemo)(() => {
    const base = {
      fontSize: 14,
      fontWeight: isSelected ? '600' : '500'
    };
    if (variant === 'outlined' && isSelected) {
      base.color = theme.colors.primaryForeground;
    } else if (isSelected) {
      base.color = theme.colors.primary;
    } else {
      base.color = theme.colors.textSecondary;
    }
    return base;
  }, [variant, isSelected, theme]);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Animated.View, {
    style: {
      transform: [{
        scale: scaleAnim
      }]
    },
    children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.Pressable, {
      style: [tabStyle, disabled && {
        opacity: 0.4
      }, style],
      onPress: handlePress,
      onPressIn: onPressIn,
      onPressOut: onPressOut,
      disabled: disabled,
      accessibilityRole: "tab",
      accessibilityState: {
        selected: isSelected,
        disabled
      },
      children: [icon, /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
        style: [labelStyle, textStyle],
        children: label
      })]
    })
  });
};
const TabPanelComponent = ({
  value,
  children,
  style
}) => {
  const {
    value: selectedValue
  } = (0, _react.useContext)(TabsContext);
  if (value !== selectedValue) return null;
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
    style: style,
    children: children
  });
};
const TabsBar = exports.TabsBar = /*#__PURE__*/(0, _react.memo)(TabsBarComponent);
TabsBar.displayName = 'TabsBar';
const Tab = exports.Tab = /*#__PURE__*/(0, _react.memo)(TabComponent);
Tab.displayName = 'Tab';
const TabPanel = exports.TabPanel = /*#__PURE__*/(0, _react.memo)(TabPanelComponent);
TabPanel.displayName = 'TabPanel';
//# sourceMappingURL=Tabs.js.map