'use strict';
import { TypeFlags, SymbolFlags } from 'typescript';
import { isExportDeclaration, isVariableDeclaration, isIdentifier, isTypeQuery, hasBodyArray } from '@flint/infra/analysis/node-type-type-guards';
import { isAsConstVariable } from '@flint/infra/analysis/variable-analysis';
import { nodeTypes, getTypeAnnotation } from '@flint/infra/analysis';
import { typeKeywords } from '../../../base-repo/constants/tools-constants.js';
import { jsBasicTypes } from '../../../base-repo/constants/basic-types.js';

var __defProp=Object['defineProperty'],__name=(_0x267b29,_0x303fda)=>__defProp(_0x267b29,'name',{'value':_0x303fda,'configurable':!![]});const enumTypeDefinitionStatuses={'notAnEnum':0x0,'valid':0x1,'invalid':0x2};function isPseudoEnumType(_0x52ae7e,_0x1c4d82){if((_0x52ae7e['flags']&TypeFlags['Object'])===-0x2678+-0xb*0x267+0x40e5)return ![];const _0x23f977=_0x52ae7e['getSymbol']();if(!_0x23f977||(_0x23f977['getFlags']()&SymbolFlags['ObjectLiteral'])===0x25db*-0x1+0x302+-0x1*-0x22d9)return ![];const _0x2382b8=_0x52ae7e['getProperties']();if(_0x2382b8['length']===-0xbff+0x7*0x416+-0x3*0x589)return ![];return _0x2382b8['every'](_0x2b9044=>{const _0x207d94=_0x2b9044['valueDeclaration'];if(!_0x207d94)return ![];const _0x200042=_0x1c4d82['getTypeOfSymbolAtLocation'](_0x2b9044,_0x207d94);return (_0x200042['flags']&TypeFlags['NumberLiteral'])!==-0xfcb+0x12cb+-0x300||(_0x200042['flags']&TypeFlags['StringLiteral'])!==-0x6c4*-0x2+-0x97b+0x1*-0x40d;});}__name(isPseudoEnumType,'isPseudoEnumType');function getAnchorNode(_0x367b22){let _0x491532=_0x367b22;const _0xeaa61=_0x367b22['parent'];return _0xeaa61&&isExportDeclaration(_0xeaa61)&&_0xeaa61['declaration']===_0x367b22&&(_0x491532=_0xeaa61),_0x491532;}__name(getAnchorNode,'getAnchorNode');function getPrecedingVariable(_0x174007,_0x440255){let _0x550b41;const _0x338d0a=_0x440255>0x303*-0x3+0xa*0x379+0x19b1*-0x1?_0x174007[_0x440255-(0x1b62+0x65*0x34+-0x2fe5)]:void(0x279+-0x117*-0x13+-0x172e);if(_0x338d0a){const _0x496ea3=isExportDeclaration(_0x338d0a)?_0x338d0a['declaration']:_0x338d0a;_0x496ea3&&isVariableDeclaration(_0x496ea3)&&(_0x550b41=_0x496ea3);}return _0x550b41;}__name(getPrecedingVariable,'getPrecedingVariable');function isValidConstant(_0x4b46ff,_0x3fbe58){return isIdentifier(_0x4b46ff['id'])&&_0x4b46ff['id']['name']===_0x3fbe58&&!isAsConstVariable(_0x4b46ff);}__name(isValidConstant,'isValidConstant');function getEnumConstantNameFromAnnotation(_0x167433){let _0x2fac4b;if(_0x167433['type']===nodeTypes['TSIndexedAccessType']&&_0x167433['indexType']['type']===nodeTypes['TSTypeOperator']&&_0x167433['indexType']['operator']===typeKeywords['keyof']){const _0x3fe6e3=_0x167433['objectType'],_0x2224c2=getTypeAnnotation(_0x3fe6e3);if(isTypeQuery(_0x3fe6e3)&&isIdentifier(_0x3fe6e3['exprName']))_0x2fac4b=_0x3fe6e3['exprName']['name'];else {if(_0x2224c2&&isTypeQuery(_0x2224c2)){const _0x48150f=_0x2224c2;isIdentifier(_0x48150f['exprName'])&&(_0x2fac4b=_0x48150f['exprName']['name']);}}}return _0x2fac4b;}__name(getEnumConstantNameFromAnnotation,'getEnumConstantNameFromAnnotation');function isEnumTypeDefinition(_0x270f79){let _0x4700a0=enumTypeDefinitionStatuses['notAnEnum'];const _0x17652d=getAnchorNode(_0x270f79),_0x7eefb4=_0x17652d['parent'];if(_0x7eefb4&&hasBodyArray(_0x7eefb4)){const _0x16d43b=_0x7eefb4['body'],_0x100274=_0x16d43b['findIndex'](_0x58f4fa=>_0x58f4fa===_0x17652d),_0x57bbe5=getEnumConstantNameFromAnnotation(_0x270f79['typeAnnotation']);if(_0x100274!==-(-0x169*-0x16+0x1a00+-0x3905)&&_0x57bbe5){const _0x353178=getPrecedingVariable(_0x16d43b,_0x100274),_0x4c1a11=!!_0x353178&&_0x353178['declarations']['some'](_0x33bb13=>isValidConstant(_0x33bb13,_0x57bbe5)||isIdentifier(_0x33bb13['id'])&&_0x33bb13['id']['name']===_0x57bbe5&&isAsConstVariable(_0x33bb13));_0x4700a0=_0x4c1a11?enumTypeDefinitionStatuses['valid']:enumTypeDefinitionStatuses['invalid'];}}return _0x4700a0;}__name(isEnumTypeDefinition,'isEnumTypeDefinition');function isNumericEnumLike(_0x5f3d80){let _0x2a6f7b;if(_0x5f3d80['type']===nodeTypes['variableDeclarator'])_0x2a6f7b=_0x5f3d80['init'];else _0x5f3d80['type']===nodeTypes['property']&&(_0x2a6f7b=_0x5f3d80['value']);while(_0x2a6f7b&&(_0x2a6f7b['type']===nodeTypes['TSAsExpression']||_0x2a6f7b['type']===nodeTypes['TSSatisfiesExpression'])){_0x2a6f7b=_0x2a6f7b['expression'];}if(_0x2a6f7b&&_0x2a6f7b['type']===nodeTypes['objectExpression']){const _0x2134ca=_0x2a6f7b['properties']['filter'](_0x594dd1=>_0x594dd1['type']===nodeTypes['property']);return _0x2134ca['length']>-0x1b7f+-0x99*-0x3c+-0x85d&&_0x2134ca['every'](_0x2a6506=>_0x2a6506['value']['type']===nodeTypes['literal']&&typeof _0x2a6506['value']['value']===jsBasicTypes['number']);}return ![];}__name(isNumericEnumLike,'isNumericEnumLike');

export { enumTypeDefinitionStatuses, getAnchorNode, getEnumConstantNameFromAnnotation, getPrecedingVariable, isEnumTypeDefinition, isNumericEnumLike, isPseudoEnumType, isValidConstant };
