'use strict';
import { ESLintUtils } from '@typescript-eslint/utils';
import { nodeTypes, isReactMethodCall, hasJSXReturn } from '@flint/infra/analysis';
import { ruleTypes, url } from '@flint/infra/constants/rules-meta';

var __defProp=Object['defineProperty'],__name=(_0x3bf6c9,_0x395ad3)=>__defProp(_0x3bf6c9,'name',{'value':_0x395ad3,'configurable':!![]});const ruleName='must-use-function-for-component';const constants={'messageId':'mustUseFunctionForComponent','meta':{'type':ruleTypes['problem'],'docs':{'description':'React\x20components\x20must\x20be\x20declared\x20using\x20function\x20declarations'},'messages':{'mustUseFunctionForComponent':ruleName+'\x0a###\x20**Must**\x20declare\x20React\x20components\x20using\x20function\x20declarations.\x0a\x0aAvoid\x20arrow\x20functions\x20and\x20React.FC\x20for\x20components.\x0a\x0a####\x20Wrong\x0a\x0aconst\x20Component\x20=\x20()\x20=>\x20{\x0a\x20\x20\x20\x20return\x20<span>Hello</span>;\x0a};\x0a\x0a####\x20Correct\x0a\x0afunction\x20Component()\x20{\x0a\x20\x20\x20\x20return\x20<span>Hello</span>;\x0a}\x0a\x0a####\x20Why\x0a\x0aUsing\x20function\x20declarations\x20for\x20React\x20components\x20improves\x20stack\x20traces,\x20debuggability,\x20and\x20consistency.\x20Arrow\x20functions\x20and\x20React.FC\x20provide\x20no\x20runtime\x20benefits\x20and\x20can\x20make\x20code\x20harder\x20to\x20analyze.'},'schema':[]},'ids':{'createElement':'createElement'}},createRule=ESLintUtils['RuleCreator'](_0x141369=>''+url+_0x141369),mustUseFunctionForComponent=createRule({'name':ruleName,'meta':constants['meta'],'defaultOptions':[],'create'(_0x7da195){return {'ArrowFunctionExpression'(_0xad7e84){const _0x8f60ff=findParentVariableDeclarator(_0xad7e84);if(!_0x8f60ff)return;if(!isTopLevelComponent(_0x8f60ff))return;if(_0x8f60ff&&(isLowercaseNamedArrow(_0x8f60ff)||isWrappedWithHttpWrapper(_0x8f60ff)))return;hasJSXReturn(_0xad7e84)&&shouldReport(_0x7da195,_0xad7e84),_0xad7e84['body']['type']===nodeTypes['callExpression']&&isReactMethodCall(_0xad7e84['body'],constants['ids']['createElement'])&&shouldReport(_0x7da195,_0xad7e84);},'ReturnStatement'(_0x58d36b){const _0x504c84=findParentVariableDeclarator(_0x58d36b);_0x504c84&&!isLowercaseNamedArrow(_0x504c84)&&_0x58d36b['argument']&&_0x58d36b['argument']['type']===nodeTypes['callExpression']&&isReactMethodCall(_0x58d36b['argument'],constants['ids']['createElement'])&&shouldReport(_0x7da195,_0x504c84);}};}});function shouldReport(_0x35e0bf,_0x13eb53){_0x35e0bf['report']({'node':_0x13eb53,'messageId':constants['messageId']});}__name(shouldReport,'shouldReport');function isWrappedWithHttpWrapper(_0x5846bb){if(_0x5846bb['type']!==nodeTypes['variableDeclarator'])return ![];const _0x5b95f5=_0x5846bb['init'];if(!_0x5b95f5||_0x5b95f5['type']!==nodeTypes['callExpression'])return ![];const _0x445a03=_0x5b95f5['callee'];return _0x445a03['type']===nodeTypes['identifier']&&_0x445a03['name']==='httpWrapper';}__name(isWrappedWithHttpWrapper,'isWrappedWithHttpWrapper');function findParentVariableDeclarator(_0x59c1c3){let _0x2a4a0a=_0x59c1c3,_0x1f01d5;while(_0x2a4a0a&&!_0x1f01d5){_0x2a4a0a['type']===nodeTypes['variableDeclarator']?_0x1f01d5=_0x2a4a0a:_0x2a4a0a=_0x2a4a0a['parent']??void(0x2*-0x449+0x2257+-0x9*0x2dd);}return _0x1f01d5;}__name(findParentVariableDeclarator,'findParentVariableDeclarator');function isTopLevelComponent(_0x13ce57){if(_0x13ce57['type']!==nodeTypes['variableDeclarator'])return ![];const _0x37e666=_0x13ce57['parent'];if(!_0x37e666||_0x37e666['type']!==nodeTypes['variableDeclaration'])return ![];const _0x1b5d77=_0x37e666['parent'];if(!_0x1b5d77)return ![];return _0x1b5d77['type']===nodeTypes['program']||_0x1b5d77['type']===nodeTypes['exportNamedDeclaration']||_0x1b5d77['type']===nodeTypes['exportDefaultDeclaration'];}__name(isTopLevelComponent,'isTopLevelComponent');function isLowercaseNamedArrow(_0x1f6919){return _0x1f6919&&_0x1f6919['type']===nodeTypes['variableDeclarator']&&_0x1f6919['id']['type']===nodeTypes['identifier']&&/^[a-z]/['test'](_0x1f6919['id']['name']);}__name(isLowercaseNamedArrow,'isLowercaseNamedArrow');

export { mustUseFunctionForComponent as default, ruleName };
