'use strict';
import { createEslintRule } from '@flint/infra/create-eslint-rule';
import { nodeTypes, iterateDescendants, isStringLiteral } from '@flint/infra/analysis';
import { jsxAttributeNames } from '@flint/infra/constants/eslint-syntax-names';
import { colorNames } from '../../../base-repo/constants/tools-constants.js';
import { first } from '../../../fd-toolbox/server/collections/single-funcs.js';

var __defProp=Object['defineProperty'],__name=(_0x274bd3,_0x46f14a)=>__defProp(_0x274bd3,'name',{'value':_0x46f14a,'configurable':!![]});const ruleName='must-use-color-variables-instead-of-hardcoded-values';const ruleContent='\x0a###\x20**Must**\x20use\x20color\x20variables\x20instead\x20of\x20hardcoded\x20values.\x0a\x0a####\x20Wrong\x0a\x0a<div\x20className=\x22bg-[#CBD6E2]\x22>Content</div>\x0a\x0a####\x20Correct\x0a\x0a<div\x20className=\x22bg-background\x22>Content</div>\x0a\x0a####\x20Why\x0a\x0aUsing\x20CSS\x20variables\x20for\x20colors\x20enhances\x20maintainability,\x20ensures\x20consistency\x20across\x20the\x20design,\x20and\x20simplifies\x20the\x20process\x20of\x20updating\x20themes\x20or\x20color\x20schemes.',twColorNames=new Set(Object['values'](colorNames)),arbitraryColorMatchers={'classWithArbitraryValue':/\b(?:\w+:)*(?:text|bg|border(?:-[trblyx])?)-(\[[^\]]+\])/g,'hexColor':/^#[0-9a-f]{3,6}$/i,'colorFunction':/^(rgb|rgba|hsl|hsla|color)\(.+\)$/i};var mustUseColorVariablesInsteadOfHardcodedValues = createEslintRule(ruleName,ruleContent,__name(function create(_0x29354e){const _0x267093=_0x29354e['sourceCode'];return {'JSXAttribute'(_0x2ddb48){if(_0x2ddb48['name']['type']!==nodeTypes['JSXIdentifier']||_0x2ddb48['name']['name']!==jsxAttributeNames['stylingClass']||!_0x2ddb48['value'])return;handleNode(_0x29354e,_0x2ddb48['value']);for(const _0x1bdd93 of iterateDescendants(_0x2ddb48['value'],_0x267093['visitorKeys'])){handleNode(_0x29354e,_0x1bdd93['value']);}}};},'create'));function handleNode(_0x5495c9,_0x38417b){if(isStringLiteral(_0x38417b))handleClassNames(_0x5495c9,_0x38417b,_0x38417b['value']);else _0x38417b['type']===nodeTypes['templateLiteral']&&handleClassNames(_0x5495c9,_0x38417b,buildMaskedTemplateLiteral(_0x38417b));}__name(handleNode,'handleNode');function handleClassNames(_0x455a3b,_0x354b21,_0x564533){const _0x2a76d0=_0x455a3b['sourceCode'];for(const _0x1d020b of _0x564533['matchAll'](arbitraryColorMatchers['classWithArbitraryValue'])){const _0x207ce0=_0x1d020b[-0x208b*0x1+0x12ca+0xdc2],_0x4a4487=_0x207ce0['slice'](0x1946+0x265*0xa+-0x3137,-(-0xc91*-0x2+-0x13eb+-0x3a*0x17));if(twColorNames['has'](_0x4a4487)||Object['values'](arbitraryColorMatchers)['some'](_0x291f8c=>_0x291f8c['test'](_0x4a4487))){const _0x16edac=first(_0x1d020b),_0x17fee7=first(_0x354b21['range'])+(0xb*0x4d+-0x8*-0x2b9+0xc8b*-0x2)+_0x1d020b['index']+_0x16edac['indexOf'](_0x207ce0),_0x2c97bb=_0x2a76d0['getLocFromIndex'](_0x17fee7),_0x210228=_0x2a76d0['getLocFromIndex'](_0x17fee7+_0x207ce0['length']);_0x455a3b['report']({'node':_0x354b21,'messageId':ruleName,'loc':{'start':_0x2c97bb,'end':_0x210228}});}}}__name(handleClassNames,'handleClassNames');function buildMaskedTemplateLiteral(_0x5f3675){return _0x5f3675['quasis']['map']((_0x5c466c,_0x19671d)=>{const _0x17fb23=_0x5f3675['expressions'][_0x19671d];return [_0x5c466c['value']['raw'],_0x17fb23?'${'+'\x20'['repeat'](_0x17fb23['range'][-0x4*-0x2a9+-0xf5+-0x9ae]-first(_0x17fb23['range']))+'}':'']['join']('');})['join']('');}__name(buildMaskedTemplateLiteral,'buildMaskedTemplateLiteral');

export { mustUseColorVariablesInsteadOfHardcodedValues as default, ruleName };
