'use strict';
import { ESLintUtils } from '@typescript-eslint/utils';
import { reactComponentTypeNames, getVariableInScope, nodeTypes, getVariableDeclaratorTypeReference, isReactFCType, getTypeReferenceTypeArguments } from '@flint/infra/analysis';
import { ruleTypes, flintConstants, url } from '@flint/infra/constants/rules-meta';
import { firstOrUndefined } from '../../../fd-toolbox/server/collections/single-funcs.js';

var __defProp=Object['defineProperty'],__name=(_0x18c272,_0x932887)=>__defProp(_0x18c272,'name',{'value':_0x932887,'configurable':!![]});const ruleName='must-use-interface-for-props';const constants={'messageId':'useInterface','react':{'namespace':flintConstants['react'],'fcComponent':reactComponentTypeNames['functionComponent']},'typeKeys':{'suggestion':ruleTypes['suggestion']}},createRule=ESLintUtils['RuleCreator'](_0x537650=>''+url+_0x537650),mustUseInterfaceForProps=createRule({'name':ruleName,'meta':{'type':constants['typeKeys']['suggestion'],'docs':{'description':'Enforce\x20using\x20interfaces\x20for\x20React\x20component\x20props'},'messages':{[constants['messageId']]:ruleName+'\x0a###\x20**Must**\x20use\x20interface\x20instead\x20of\x20type\x20alias\x20for\x20React\x20component\x20props.\x0a\x0a####\x20Wrong\x0a\x0a```ts\x0atype\x20Props\x20=\x20{\x0a\x20\x20\x20\x20title:\x20string;\x0a};\x0a\x0aconst\x20Component:\x20React.FC<Props>\x20=\x20({\x20title\x20})\x20=>\x20<h1>{title}</h1>;\x0a```\x0a\x0a####\x20Correct\x0a\x0a```ts\x0ainterface\x20Props\x20{\x0a\x20\x20\x20\x20title:\x20string;\x0a}\x0a\x0aconst\x20Component:\x20React.FC<Props>\x20=\x20({\x20title\x20})\x20=>\x20<h1>{title}</h1>;\x0a```\x0a\x0a####\x20Why\x0a\x0aInterfaces\x20are\x20the\x20recommended\x20way\x20to\x20define\x20props\x20in\x20React.\x20They\x20are\x20easier\x20to\x20extend,\x20more\x20readable,\x20and\x20better\x20supported\x20by\x20TypeScript\x20tools.'},'schema':[]},'defaultOptions':[],'create'(_0x2f3b87){return {'VariableDeclarator'(_0x34d2f3){const {shouldProcess:_0x36f589,propType:_0x5836c2,definition:_0x5a1757}=shouldReportVariableDeclarator(_0x34d2f3,_0x2f3b87['sourceCode']);_0x36f589&&_0x5836c2&&_0x5a1757&&(_0x2f3b87['report']({'node':_0x5836c2,'messageId':constants['messageId']}),_0x2f3b87['report']({'node':_0x5a1757,'messageId':constants['messageId']}));}};}});function findTypeDefinition(_0x47ebec,_0x558dc8,_0x5d77ed){const _0xe337ff=getVariableInScope(_0x5d77ed,_0x558dc8,_0x47ebec)?.['defs']?.['at'](-0x1*0x26ff+0x115c+0x15a3),_0x21e304=_0xe337ff?.['node'];return _0x21e304;}__name(findTypeDefinition,'findTypeDefinition');function getPropType(_0x1c5cf5){let _0x18d311;const _0xb19e26=firstOrUndefined(_0x1c5cf5);return _0xb19e26&&_0xb19e26['type']===nodeTypes['TSTypeReference']&&_0xb19e26['typeName']&&_0xb19e26['typeName']['type']===nodeTypes['identifier']&&(_0x18d311=_0xb19e26),_0x18d311;}__name(getPropType,'getPropType');function getTypeAliasDefinition(_0x3c7d02,_0x11ca0a,_0x47238d){let _0xe46d16;if(_0x3c7d02['typeName']['type']===nodeTypes['identifier']){const _0x364cb6=findTypeDefinition(_0x3c7d02['typeName']['name'],_0x11ca0a,_0x47238d);_0x364cb6&&_0x364cb6['type']===nodeTypes['TSTypeAliasDeclaration']&&(_0xe46d16=_0x364cb6);}return _0xe46d16;}__name(getTypeAliasDefinition,'getTypeAliasDefinition');function shouldReportVariableDeclarator(_0x4079b6,_0x2b4f36){let _0xd2040f=![],_0x4706ae,_0x2cc16a;const _0x4c4786=getVariableDeclaratorTypeReference(_0x4079b6);if(_0x4c4786&&isReactFCType(_0x4c4786)){const _0x4566e5=getTypeReferenceTypeArguments(_0x4c4786),_0x2c4cd6=_0x4566e5['length']?getPropType(_0x4566e5):void(0x1*-0x16f1+-0x1bf4+0x32e5);if(_0x2c4cd6){const _0x5b638c=getTypeAliasDefinition(_0x2c4cd6,_0x4079b6,_0x2b4f36);_0x5b638c&&(_0x4706ae=_0x2c4cd6,_0x2cc16a=_0x5b638c,_0xd2040f=!![]);}}return {'shouldProcess':_0xd2040f,'propType':_0x4706ae,'definition':_0x2cc16a};}__name(shouldReportVariableDeclarator,'shouldReportVariableDeclarator');

export { mustUseInterfaceForProps as default, ruleName };
