import checkExportInIndexFile from './checkExportInIndexFile.js';

/**
 * Check if a component is exported in the index file
 * @param {string} indexContent - Content of index.ts
 * @param {string} componentName - Name of the component to check
 * @returns {boolean} True if the component is exported
 */
export default function checkComponentExportInIndex(indexContent, componentName) {
  // Pattern to check for exporting correctly component name
  const exportPatterns = [
    new RegExp(`export\\s+{[^}]*\\b${componentName}\\b[^}]*}\\s+from\\s+['"]\\./${componentName}['"]`, 'mi'),
    new RegExp(`export\\s+\\*\\s+from\\s+['"]\\./${componentName}['"]`, 'mi'),
    new RegExp(`export\\s+{[^}]*\\b${componentName}\\b[^}]*}`, 'mi'),
    new RegExp(`export\\s+default\\s+${componentName}`, 'mi'),
  ];

  // Make sure the checking file is exported
  const hasNodeExported = checkExportInIndexFile(indexContent, componentName);
  if (hasNodeExported) {
    return true;
  }

  return exportPatterns.some(pattern => pattern.test(indexContent));
}
