/*
 * Copyright (c) 2018, 2025, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 */
const Utils=require("../jetwc-lib/jetwcutils-componentAuditUtils");const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-css-oj-complete"};ruleDef.prototype.getShortDescription=function(){return"Verify that a component CSS implementation includes the standard definition for hiding itself before it is fully initialized"};ruleDef.prototype.getDescription=function(){return"All custom components should include a selector definition for the component tag that ensures that it is hidden until the oj-complete marker class is applied. This is managed through the use of the :not(.oj-complete) pseudo-class setting the visibility to hidden"};ruleDef.prototype.register=function(context){return{startaudit:this._ruleSetup,"css-selector":this._detectNotSelector,endaudit:this._reportUnmatchedComponents}};ruleDef.prototype._ruleSetup=function(context){this.validOjCompleteSelectors=new Set};ruleDef.prototype._detectNotSelector=function(context,selector){if(selector.type==="Selector"&&selector.children.length===2&&selector.children[0].type==="TypeSelector"&&selector.children[1].type==="PseudoClassSelector"&&selector.children[1].name==="not"){const selectorComponentName=selector.children[0].name;const componentInfo=Utils.componentInfo(context,selectorComponentName);if(componentInfo&&selector.children[1].children.length>0&&selector.children[1].children[0].type==="SelectorList"&&selector.children[1].children[0].children.length>0&&selector.children[1].children[0].children[0].type==="Selector"&&selector.children[1].children[0].children[0].children.length>0&&selector.children[1].children[0].children[0].children[0].type==="ClassSelector"&&selector.children[1].children[0].children[0].children[0].name==="oj-complete"){this.validOjCompleteSelectors.add(selectorComponentName)}}};ruleDef.prototype._reportUnmatchedComponents=function(context){let allComponents;if(context.rulePack.getExtension()){allComponents=context.rulePack.getExtension().allComponents}if(allComponents){for(const[componentName,componentDef]of allComponents.entries()){if(componentDef.local&&componentDef.type==="composite"){const fullName=componentDef.fullName;if(!this.validOjCompleteSelectors.has(fullName)){if(!Utils.shouldIgnoreCheck(context,this.getName(),fullName)){const issue=new context.Issue(`Component '${fullName}' does not have a defined CSS sector for :not(.oj-complete)`);context.reporter.addIssue(issue,context)}}}}}};module.exports=ruleDef;