"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ModuleAttachment = void 0;
var _react = require("react");
var _context = require("../../context");
var _core = require("../../core");
var _badge = require("../badge");
var _icons = require("../icons");
var _layout = require("../layout");
var _loadingSpinner = require("../loadingSpinner");
var _skeleton = require("../skeleton");
var _typography = require("../typography");
var _ModuleStatic = require("./ModuleStatic");
var _PressableModuleBase = require("./PressableModuleBase");
var _jsxRuntime = require("react/jsx-runtime");
const ModuleAttachmentContent = ({
  isFetching,
  format,
  title,
  testID
}) => {
  const theme = (0, _context.useIOTheme)();
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_layout.HStack, {
    space: 8,
    style: {
      alignItems: "center"
    },
    children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_layout.VStack, {
      space: 4,
      style: {
        alignItems: "flex-start",
        flexShrink: 1,
        flexGrow: 1
      },
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_typography.Body, {
        weight: "Semibold",
        numberOfLines: 2,
        color: theme["interactiveElem-default"],
        children: title
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_badge.Badge, {
        text: format.toUpperCase(),
        variant: "default"
      })]
    }), isFetching ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_loadingSpinner.LoadingSpinner, {
      testID: testID ? `${testID}_activityIndicator` : undefined
    }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.Icon, {
      name: "chevronRightListItem",
      color: theme["interactiveElem-default"],
      size: _core.IOListItemVisualParams.chevronSize
    })]
  });
};

/**
 * The `ModuleAttachment` component is a custom button component with an extended outline style.
 * It provides an animated scaling effect when pressed.
 *
 * @param {string}   accessibilityLabel - Optional accessibility label.
 * @param {boolean}  disabled - If true, the button is disabled.
 * @param {string}   fetchingAccessibilityLabel - Optional accessibility label to use during fetching.
 * @param {string}   loadingAccessibilityLabel - Optional accessibility label to use during loading.
 * @param {string}   format - Badge content. PDF or DOC.
 * @param {boolean}  isLoading - If true, displays a skeleton loading component.
 * @param {boolean}  isFetching - If true, displays an activity indicator.
 * @param {function} onPress - The function to be executed when the item is pressed.
 * @param {string}   testID - The test ID for testing purposes.
 * @param {string}   title - The title text to display.
 *
 */
const ModuleAttachment = ({
  accessibilityLabel,
  disabled = false,
  fetchingAccessibilityLabel,
  loadingAccessibilityLabel,
  format,
  isLoading = false,
  isFetching = false,
  onPress,
  testID,
  title
}) => {
  const handleOnPress = (0, _react.useCallback)(event => {
    if (isFetching) {
      return;
    }
    onPress(event);
  }, [isFetching, onPress]);
  if (isLoading) {
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(ModuleAttachmentSkeleton, {
      loadingAccessibilityLabel: loadingAccessibilityLabel
    });
  }
  const pressableAccessibilityLabel = (isFetching && !!fetchingAccessibilityLabel ? fetchingAccessibilityLabel : accessibilityLabel) ?? title;
  return disabled || isFetching ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_ModuleStatic.ModuleStatic, {
    disabled: disabled,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ModuleAttachmentContent, {
      isFetching: isFetching,
      title: title,
      format: format
    })
  }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_PressableModuleBase.PressableModuleBase, {
    testID: testID,
    onPress: handleOnPress,
    accessibilityHint: format,
    accessibilityLabel: pressableAccessibilityLabel,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ModuleAttachmentContent, {
      isFetching: isFetching,
      title: title,
      format: format
    })
  });
};
exports.ModuleAttachment = ModuleAttachment;
const ModuleAttachmentSkeleton = ({
  loadingAccessibilityLabel
}) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_ModuleStatic.ModuleStatic, {
  accessible: true,
  accessibilityLabel: loadingAccessibilityLabel,
  accessibilityState: {
    busy: true
  },
  startBlock: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_layout.VStack, {
    space: 4,
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_skeleton.IOSkeleton, {
      shape: "rectangle",
      radius: 8,
      width: 114,
      height: 16
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_skeleton.IOSkeleton, {
      shape: "rectangle",
      radius: 16,
      width: 42,
      height: 20
    })]
  })
});
//# sourceMappingURL=ModuleAttachment.js.map