"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.TabNavigation = void 0;
var _react = require("react");
var _reactNative = require("react-native");
var _reactNativeGestureHandler = require("react-native-gesture-handler");
var _core = require("../../core");
var _jsxRuntime = require("react/jsx-runtime");
const itemsJustify = {
  start: "flex-start",
  center: "center",
  end: "flex-end",
  stretch: "space-between"
};
const TabNavigation = ({
  color = "light",
  selectedIndex,
  tabAlignment = "center",
  onItemPress,
  children,
  includeContentMargins = true
}) => {
  const [itemMinWidth, setItemMinWidth] = (0, _react.useState)(0);
  const handleItemOnLayout = event => {
    const {
      width
    } = event.nativeEvent.layout;
    setItemMinWidth(current => Math.max(current, width));
  };
  const stretchItems = tabAlignment === "stretch";
  const wrapChild = (child, index = 0) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
    style: [styles.item, stretchItems && {
      minWidth: itemMinWidth
    }],
    onLayout: handleItemOnLayout,
    children: /*#__PURE__*/(0, _react.cloneElement)(child, {
      onPress: event => {
        child.props.onPress?.(event);
        onItemPress?.(index);
      },
      selected: selectedIndex === index,
      color
    })
  }, child.props.label);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeGestureHandler.ScrollView, {
    horizontal: true,
    centerContent: true,
    showsHorizontalScrollIndicator: false,
    contentContainerStyle: [includeContentMargins ? {
      paddingHorizontal: _core.IOVisualCostants.appMarginDefault
    } : {}, {
      flexGrow: 1,
      justifyContent: itemsJustify[tabAlignment],
      gap: 8
    }],
    children: Array.isArray(children) ? children.map(wrapChild) : wrapChild(children)
  });
};
exports.TabNavigation = TabNavigation;
const styles = _reactNative.StyleSheet.create({
  item: {
    flexGrow: 0,
    flexShrink: 1,
    flexBasis: 100,
    alignItems: "center"
  }
});
//# sourceMappingURL=TabNavigation.js.map