"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _reactNative = require("react-native");
var _vectorIcons = require("@expo/vector-icons");
var _jsxRuntime = require("react/jsx-runtime");
const GroupedPillButtons = ({
  buttons,
  colors,
  gap = 8
}) => {
  const getButtonStyle = (button, index, totalButtons) => {
    const baseStyle = {
      flexDirection: 'row',
      alignItems: 'center',
      paddingVertical: 6,
      paddingHorizontal: 12,
      gap: 6,
      minWidth: 70,
      borderWidth: 1,
      flexShrink: 0,
      ..._reactNative.Platform.select({
        web: {
          boxShadow: '0 2px 4px rgba(0,0,0,0.1)'
        },
        default: {
          shadowOffset: {
            width: 0,
            height: 2
          },
          shadowOpacity: 0.1,
          shadowRadius: 4,
          elevation: 2
        }
      })
    };

    // Determine border radius based on position
    let borderRadius = {
      borderTopLeftRadius: 35,
      borderBottomLeftRadius: 35,
      borderTopRightRadius: 35,
      borderBottomRightRadius: 35
    };
    if (totalButtons > 1) {
      if (index === 0) {
        // First button
        borderRadius = {
          borderTopLeftRadius: 35,
          borderBottomLeftRadius: 35,
          borderTopRightRadius: 12,
          borderBottomRightRadius: 12
        };
      } else if (index === totalButtons - 1) {
        // Last button
        borderRadius = {
          borderTopLeftRadius: 12,
          borderBottomLeftRadius: 12,
          borderTopRightRadius: 35,
          borderBottomRightRadius: 35
        };
      } else {
        // Middle button (if 3 buttons)
        borderRadius = {
          borderTopLeftRadius: 12,
          borderBottomLeftRadius: 12,
          borderTopRightRadius: 12,
          borderBottomRightRadius: 12
        };
      }
    }

    // Determine colors based on variant
    let backgroundColor = 'transparent';
    let borderColor = colors.border;
    let shadowColor = colors.border;
    let textColor = colors.text;
    switch (button.variant) {
      case 'primary':
        backgroundColor = colors.primary;
        borderColor = colors.primary;
        shadowColor = colors.primary;
        textColor = '#FFFFFF';
        break;
      case 'secondary':
        backgroundColor = colors.secondary || colors.primary;
        borderColor = colors.secondary || colors.primary;
        shadowColor = colors.secondary || colors.primary;
        textColor = '#FFFFFF';
        break;
      case 'transparent':
      default:
        backgroundColor = 'transparent';
        borderColor = colors.border;
        shadowColor = colors.border;
        textColor = colors.text;
        break;
    }
    return {
      ...baseStyle,
      ...borderRadius,
      backgroundColor,
      borderColor,
      shadowColor
    };
  };
  const getTextStyle = (button, colors) => {
    const baseTextStyle = {
      fontSize: 15,
      fontWeight: '600',
      // Avoid stretching that can cause wraps on native
      flexShrink: 1
    };
    let textColor = colors.text;
    switch (button.variant) {
      case 'primary':
      case 'secondary':
        textColor = '#FFFFFF';
        break;
      case 'transparent':
      default:
        textColor = colors.text;
        break;
    }
    return {
      ...baseTextStyle,
      color: textColor,
      ...(_reactNative.Platform.OS === 'web' ? {
        whiteSpace: 'nowrap'
      } : null)
    };
  };
  const getIconColor = (button, colors) => {
    switch (button.variant) {
      case 'primary':
      case 'secondary':
        return '#FFFFFF';
      case 'transparent':
      default:
        return colors.text;
    }
  };
  const isBackButton = button => {
    const text = typeof button.text === 'string' ? button.text.toLowerCase() : '';
    return text.includes('back') || button.icon === 'arrow-back' || button.icon === 'chevron-back';
  };
  const renderButtonContent = (button, colors, index) => {
    const iconColor = getIconColor(button, colors);
    const isBack = isBackButton(button);
    const isFirstButton = index === 0;
    const isSingleButton = buttons.length === 1;
    if (button.loading) {
      return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.ActivityIndicator, {
        color: iconColor,
        size: "small"
      });
    }

    // Auto-detect icon placement based on button order and type
    if (isSingleButton) {
      // Single button: icon on right
      return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
          style: getTextStyle(button, colors),
          numberOfLines: 1,
          ellipsizeMode: "tail",
          children: button.text
        }), button.icon && /*#__PURE__*/(0, _jsxRuntime.jsx)(_vectorIcons.Ionicons, {
          name: button.icon,
          size: 16,
          color: iconColor
        })]
      });
    } else if (isFirstButton || isBack) {
      // First button or back button: icon on left, text on right
      return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
        children: [button.icon && /*#__PURE__*/(0, _jsxRuntime.jsx)(_vectorIcons.Ionicons, {
          name: button.icon,
          size: 16,
          color: iconColor
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
          style: getTextStyle(button, colors),
          numberOfLines: 1,
          ellipsizeMode: "tail",
          children: button.text
        })]
      });
    } else {
      // Second button or forward/action button: text on left, icon on right
      return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
          style: getTextStyle(button, colors),
          numberOfLines: 1,
          ellipsizeMode: "tail",
          children: button.text
        }), button.icon && /*#__PURE__*/(0, _jsxRuntime.jsx)(_vectorIcons.Ionicons, {
          name: button.icon,
          size: 16,
          color: iconColor
        })]
      });
    }
  };
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
    style: [styles.container, {
      gap
    }],
    children: buttons.map((button, index) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, {
      style: getButtonStyle(button, index, buttons.length),
      onPress: button.onPress,
      disabled: button.disabled || button.loading,
      testID: button.testID,
      children: renderButtonContent(button, colors, index)
    }, index))
  });
};
const styles = _reactNative.StyleSheet.create({
  container: {
    flexDirection: 'row',
    justifyContent: 'flex-end',
    marginTop: 16,
    marginBottom: 8,
    width: '100%'
  }
});
var _default = exports.default = GroupedPillButtons;
//# sourceMappingURL=GroupedPillButtons.js.map