'use strict';
import { createEslintRule } from '@flint/infra/create-eslint-rule';
import { isJSXIdentifier, isJSXExpressionContainer, isTemplateLiteral, nodeTypes, isStringLikeTypeNode, isMemberCallExpression, isArrayMethodCallExpression } from '@flint/infra/analysis';
import { ESLintUtils } from '@typescript-eslint/utils';
import { collectionMethodNames, wellKnownProps } from '../../../base-repo/constants/internal-common-strings.js';

var __defProp=Object['defineProperty'],__name=(_0x28fc37,_0x3b9142)=>__defProp(_0x28fc37,'name',{'value':_0x3b9142,'configurable':!![]});const ruleName='must-use-functions-for-component-ids';const ruleContent='\x0a###\x20**Must**\x20use\x20functions\x20for\x20component\x20ids.\x0a\x0a####\x20Wrong\x0a\x0aimport\x20{\x20elements\x20}\x20from\x20\x22@/meta/constants/elements.ts\x22\x0a\x0aexport\x20function\x20Foo({\x20id\x20})\x20{\x0a\x20\x20\x20\x20return\x20<div\x20id={elements.fooElementId\x20+\x20id}></div>\x0a}\x0a\x0a####\x20Correct\x0a\x0aimport\x20{\x20getFooId\x20}\x20from\x20\x22./Foo.funcs.ts\x22\x0a\x0aexport\x20function\x20Foo({\x20id\x20})\x20{\x0a\x20\x20\x20\x20return\x20<div\x20id={getFooId(id)}></div>\x0a}\x0a\x0a####\x20Why\x0a\x0aUsing\x20functions\x20instead\x20of\x20direct\x20concatenation\x20helps\x20with\x20consistency\x20and\x20prevents\x20bugs.',concatenationMethods={'string':[collectionMethodNames['concat']],'array':{'definitely':[collectionMethodNames['join']],'possibly':[collectionMethodNames['reduce'],collectionMethodNames['reduceRight']]}};var mustUseFunctionsForComponentIds = createEslintRule(ruleName,ruleContent,__name(function create(_0x245b7e){const _0x4c09f3=ESLintUtils['getParserServices'](_0x245b7e);return {'JSXAttribute'(_0xd0d7fe){if(!isJSXIdentifier(_0xd0d7fe['name'])||_0xd0d7fe['name']['name']!==wellKnownProps['id']||!_0xd0d7fe['value']||!isJSXExpressionContainer(_0xd0d7fe['value']))return;const _0x1f53c6=_0xd0d7fe['value']['expression'];(isConcatenationUsingOperator(_0x1f53c6,_0x4c09f3)||isTemplateLiteral(_0x1f53c6)&&_0x1f53c6['expressions']['length']>-0x1*0x2b9+0x67*-0x27+-0x2*-0x935||isConcatenationUsingStringMethod(_0x1f53c6,_0x4c09f3)||isConcatenationUsingArrayMethod(_0x1f53c6,_0x4c09f3)||isPossibleConcatenationUsingArrayMethod(_0x1f53c6,_0x4c09f3))&&_0x245b7e['report']({'node':_0xd0d7fe,'messageId':ruleName});}};},'create'));function isConcatenationUsingOperator(_0x53db3f,_0x4756ef){return _0x53db3f['type']===nodeTypes['binaryExpression']&&_0x53db3f['operator']==='+'&&isStringLikeTypeNode(_0x53db3f,_0x4756ef);}__name(isConcatenationUsingOperator,'isConcatenationUsingOperator');function isConcatenationUsingStringMethod(_0x285741,_0x19c0d4){return isMemberCallExpression(_0x285741)&&isStringLikeTypeNode(_0x285741['callee']['object'],_0x19c0d4)&&!_0x285741['callee']['computed']&&concatenationMethods['string']['includes'](_0x285741['callee']['property']['name']);}__name(isConcatenationUsingStringMethod,'isConcatenationUsingStringMethod');function isConcatenationUsingArrayMethod(_0x3e4ad0,_0x1ddf73){return isArrayMethodCallExpression(_0x3e4ad0,_0x1ddf73,concatenationMethods['array']['definitely']);}__name(isConcatenationUsingArrayMethod,'isConcatenationUsingArrayMethod');function isPossibleConcatenationUsingArrayMethod(_0x1085b1,_0x4532f6){return isArrayMethodCallExpression(_0x1085b1,_0x4532f6,concatenationMethods['array']['possibly'])&&isStringLikeTypeNode(_0x1085b1,_0x4532f6);}__name(isPossibleConcatenationUsingArrayMethod,'isPossibleConcatenationUsingArrayMethod');

export { mustUseFunctionsForComponentIds as default, ruleName };
