'use strict';
import { ESLintUtils } from '@typescript-eslint/utils';
import { isTestFile, getMethodNameFromCallee, isStringLiteral, isTemplateLiteral, isMemberExpression, isNameMatch } from '@flint/infra/analysis';
import { ruleTypes, url } from '@flint/infra/constants/rules-meta';
import { commonLowerCaseWords } from '../../../base-repo/constants/internal-common-strings.js';
import { flintRuleIdentifiers } from '@flint/infra/constants/shared-string-identifiers';
import { firstOrUndefined } from '../../../fd-toolbox/server/collections/single-funcs.js';

var __defProp=Object['defineProperty'],__name=(_0x34583f,_0x2ed543)=>__defProp(_0x34583f,'name',{'value':_0x2ed543,'configurable':!![]});const ruleName='must-get-elements-in-tests-only-by-id';const constants={'messageIds':{'useIdSelectorOnly':'useIdSelectorOnly'},'meta':{'type':ruleTypes['suggestion'],'docs':{'description':'Must\x20get\x20elements\x20in\x20tests\x20only\x20by\x20id\x20or\x20avoid\x20CSS\x20selectors\x20in\x20getBy*\x20methods'},'messages':{'useIdSelectorOnly':'must-get-elements-in-tests-only-by-id\x0a###\x20**Must**\x20get\x20elements\x20in\x20tests\x20only\x20by\x20id.\x0a\x0a####\x20Wrong\x0a\x0aconst\x20button\x20=\x20page.locator(\x22.btn-primary\x22);\x0aawait\x20button.click();\x0a\x0a####\x20Correct\x0a\x0aconst\x20button\x20=\x20page.locator(\x22#foo-button\x22);\x0aawait\x20button.click();\x0a\x0a####\x20Why\x0a\x0aUsing\x20id\x20ensures\x20consistent\x20and\x20reliable\x20test\x20execution,\x20reducing\x20maintenance\x20efforts\x20and\x20preventing\x20flaky\x20tests.\x20Selector-like\x20strings\x20are\x20not\x20allowed\x20in\x20getBy*\x20methods\x20either;\x20use\x20semantic\x20queries\x20there.'},'schema':[]},'testFilePatterns':[/\.test\.(ts|tsx|js|jsx)$/,/\.spec\.(ts|tsx|js|jsx)$/,/(^|[/\\])[^/\\]*test[^/\\]*[/\\]/],'cssSelectorMethods':new Set(['locator','$','$$','$eval','$$eval','$evalAll','$x',flintRuleIdentifiers['waitForSelector'],commonLowerCaseWords['filter']]),'nonCssSelectorMethods':new Set(['getByTestId','getByText','getByLabel','getByPlaceholder','getByAltText','getByTitle','getByDisplayValue']),'selectorLikeStarts':['#','.','[',':','>','+','~','xpath=','css=','//','.//','..//']},createRule=ESLintUtils['RuleCreator'](_0x524f20=>''+url+_0x524f20),mustGetElementsInTestsOnlyById=createRule({'name':ruleName,'meta':constants['meta'],'defaultOptions':[],'create'(_0x5932f0){if(!isTestFile(_0x5932f0['filename'],[...constants['testFilePatterns']]))return {};return {'CallExpression'(_0x480849){const _0x4b4f60=getMethodNameFromCallee(_0x480849['callee']);if(!_0x4b4f60)return;isGetByRoleCall(_0x480849)&&_0x5932f0['report']({'node':_0x480849,'messageId':constants['messageIds']['useIdSelectorOnly']});const _0x593af3=firstOrUndefined(_0x480849['arguments']);_0x593af3&&(constants['cssSelectorMethods']['has'](_0x4b4f60)&&isInvalidCssSelector(_0x593af3)||constants['nonCssSelectorMethods']['has'](_0x4b4f60)&&isInvalidNonCssSelector(_0x593af3))&&_0x5932f0['report']({'node':_0x593af3,'messageId':constants['messageIds']['useIdSelectorOnly']});}};}});function getStaticStringValue(_0xb79134){let _0x59319b;if(isStringLiteral(_0xb79134))_0x59319b=_0xb79134['value'];else isTemplateLiteral(_0xb79134)&&_0xb79134['expressions']['length']===-0x779*0x1+0x1*0x1123+-0x9aa&&(_0x59319b=firstOrUndefined(_0xb79134['quasis'])?.['value']['raw']);return _0x59319b;}__name(getStaticStringValue,'getStaticStringValue');function isInvalidCssSelector(_0x5cfbef){const _0x1c7fc8=getStaticStringValue(_0x5cfbef),_0x4065bb=/^\s*#[A-Za-z0-9_-]+\s*$/;if(!_0x1c7fc8)return ![];return !_0x4065bb['test'](_0x1c7fc8);}__name(isInvalidCssSelector,'isInvalidCssSelector');function isInvalidNonCssSelector(_0x2bcd82){const _0x5664e3=getStaticStringValue(_0x2bcd82),_0x11f896=/^[a-z][a-z0-9_-]*(?:[#:>.+~]|\[|\s+[>+~])/i;if(!_0x5664e3)return ![];const _0x257571=_0x5664e3['trim']();if(constants['selectorLikeStarts']['some'](_0x422ea0=>_0x257571['startsWith'](_0x422ea0)))return !![];return _0x11f896['test'](_0x257571);}__name(isInvalidNonCssSelector,'isInvalidNonCssSelector');function isGetByRoleCall(_0x181f93){return isMemberExpression(_0x181f93['callee'])&&isNameMatch(_0x181f93['callee']['property'],'getByRole');}__name(isGetByRoleCall,'isGetByRoleCall');

export { mustGetElementsInTestsOnlyById as default, ruleName };
