"use strict";

import { useCallback, useMemo } from "react";
import { View } from "react-native";
import { useIOTheme } from "../../context";
import { IOListItemStyles, IOListItemVisualParams, IOSelectionListItemVisualParams, IOVisualCostants } from "../../core";
import { useIOFontDynamicScale } from "../../utils/accessibility";
import { Badge } from "../badge";
import { IOButton, IconButton } from "../buttons";
import { Icon } from "../icons";
import { VSpacer } from "../layout";
import { BodySmall, H6 } from "../typography";
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
const iconMargin = IOVisualCostants.iconMargin;
export const ListItemHeader = ({
  label,
  iconName,
  iconColor,
  endElement,
  description,
  accessibilityLabel,
  testID
}) => {
  const theme = useIOTheme();
  const {
    dynamicFontScale,
    spacingScaleMultiplier,
    hugeFontEnabled
  } = useIOFontDynamicScale();
  const itemInfoTextComponent = useMemo(() => /*#__PURE__*/_jsx(View, {
    accessible: true,
    accessibilityRole: "header",
    accessibilityLabel: accessibilityLabel ?? label,
    children: /*#__PURE__*/_jsx(H6, {
      color: theme["textBody-tertiary"],
      children: label
    })
  }), [label, accessibilityLabel, theme]);
  const listItemAction = useCallback(() => {
    if (endElement) {
      const {
        type,
        componentProps
      } = endElement;
      switch (type) {
        case "buttonLink":
          return /*#__PURE__*/_jsx(IOButton, {
            variant: "link",
            ...componentProps
          });
        case "iconButton":
          return /*#__PURE__*/_jsx(IconButton, {
            ...componentProps
          });
        case "badge":
          return /*#__PURE__*/_jsx(Badge, {
            ...componentProps
          });
        default:
          return /*#__PURE__*/_jsx(_Fragment, {});
      }
    }
    return /*#__PURE__*/_jsx(_Fragment, {});
  }, [endElement]);
  return /*#__PURE__*/_jsxs(View, {
    style: IOListItemStyles.listItem,
    testID: testID,
    children: [/*#__PURE__*/_jsxs(View, {
      style: IOListItemStyles.listItemInner,
      children: [iconName && !hugeFontEnabled && /*#__PURE__*/_jsx(View, {
        style: {
          marginRight: iconMargin * dynamicFontScale * spacingScaleMultiplier
        },
        children: /*#__PURE__*/_jsx(Icon, {
          allowFontScaling: true,
          name: iconName,
          color: iconColor ?? theme["icon-decorative"],
          size: IOListItemVisualParams.iconSize
        })
      }), /*#__PURE__*/_jsx(View, {
        style: {
          flex: 1
        },
        children: itemInfoTextComponent
      }), endElement && /*#__PURE__*/_jsx(View, {
        style: {
          marginLeft: IOListItemVisualParams.actionMargin
        },
        children: listItemAction()
      })]
    }), description && /*#__PURE__*/_jsxs(View, {
      children: [/*#__PURE__*/_jsx(VSpacer, {
        size: IOSelectionListItemVisualParams.descriptionMargin
      }), /*#__PURE__*/_jsx(BodySmall, {
        weight: "Regular",
        color: theme["textBody-tertiary"],
        children: description
      })]
    })]
  });
};
//# sourceMappingURL=ListItemHeader.js.map