"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ListItemHeader = void 0;
var _react = require("react");
var _reactNative = require("react-native");
var _context = require("../../context");
var _core = require("../../core");
var _accessibility = require("../../utils/accessibility");
var _badge = require("../badge");
var _buttons = require("../buttons");
var _icons = require("../icons");
var _layout = require("../layout");
var _typography = require("../typography");
var _jsxRuntime = require("react/jsx-runtime");
const iconMargin = _core.IOVisualCostants.iconMargin;
const ListItemHeader = ({
  label,
  iconName,
  iconColor,
  endElement,
  description,
  accessibilityLabel,
  testID
}) => {
  const theme = (0, _context.useIOTheme)();
  const {
    dynamicFontScale,
    spacingScaleMultiplier,
    hugeFontEnabled
  } = (0, _accessibility.useIOFontDynamicScale)();
  const itemInfoTextComponent = (0, _react.useMemo)(() => /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
    accessible: true,
    accessibilityRole: "header",
    accessibilityLabel: accessibilityLabel ?? label,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_typography.H6, {
      color: theme["textBody-tertiary"],
      children: label
    })
  }), [label, accessibilityLabel, theme]);
  const listItemAction = (0, _react.useCallback)(() => {
    if (endElement) {
      const {
        type,
        componentProps
      } = endElement;
      switch (type) {
        case "buttonLink":
          return /*#__PURE__*/(0, _jsxRuntime.jsx)(_buttons.IOButton, {
            variant: "link",
            ...componentProps
          });
        case "iconButton":
          return /*#__PURE__*/(0, _jsxRuntime.jsx)(_buttons.IconButton, {
            ...componentProps
          });
        case "badge":
          return /*#__PURE__*/(0, _jsxRuntime.jsx)(_badge.Badge, {
            ...componentProps
          });
        default:
          return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {});
      }
    }
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {});
  }, [endElement]);
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
    style: _core.IOListItemStyles.listItem,
    testID: testID,
    children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
      style: _core.IOListItemStyles.listItemInner,
      children: [iconName && !hugeFontEnabled && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
        style: {
          marginRight: iconMargin * dynamicFontScale * spacingScaleMultiplier
        },
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.Icon, {
          allowFontScaling: true,
          name: iconName,
          color: iconColor ?? theme["icon-decorative"],
          size: _core.IOListItemVisualParams.iconSize
        })
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
        style: {
          flex: 1
        },
        children: itemInfoTextComponent
      }), endElement && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
        style: {
          marginLeft: _core.IOListItemVisualParams.actionMargin
        },
        children: listItemAction()
      })]
    }), description && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_layout.VSpacer, {
        size: _core.IOSelectionListItemVisualParams.descriptionMargin
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_typography.BodySmall, {
        weight: "Regular",
        color: theme["textBody-tertiary"],
        children: description
      })]
    })]
  });
};
exports.ListItemHeader = ListItemHeader;
//# sourceMappingURL=ListItemHeader.js.map