/*
 * 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 RULE_NAME="oj-html-wctag-id";const SHORT_DESCRIPT="Custom components should not used a hard-coded 'id' attribute and should be set to an expression";const LONG_DESCRIPT="Hard-coded element IDs should not be used within custom components and should be set to an expression. Element IDs must be unique for each instance of the component. See context.uniqueId in the custom element documentation for information on how to derive unique IDs for elements."+"<p>If a CCA implements hard-coded IDs for HTML elements in the CCA view, e.g.<p>"+"<oj-input id=\"foo\"><p>"+"then this is guaranteed to cause issues as soon as more than one instance of "+"the component is used on the page (plus there is a significant risk of "+"collision with other IDs in the page as a whole.";const ID="id";const COLON_ID=":id";class Rule{getName(){return RULE_NAME}getDescription(){return LONG_DESCRIPT}getShortDescription(){return SHORT_DESCRIPT}register(){return{"webcomp":this._onTag}}_onTag(ruleCtx,tag){var attribs,idAttr,isId,isColonId,isExpr,isLit,av,val,msg,mid;if(!ruleCtx.ojTag||!ruleCtx.filepath.includes("jet-composites")||!ruleCtx.tagNode.attribs){return}if(ruleCtx.utils.metaLib.isBindingTag(tag)){return}attribs=ruleCtx.tagNode.attribs;isId=attribs.hasOwnProperty(ID);isColonId=attribs.hasOwnProperty(COLON_ID);if(!isId&&!isColonId){return}idAttr=isId?ID:COLON_ID;av=attribs[idAttr];isExpr=_isAttrExpr(av);val=isExpr?_stripExprDelims(av):av;isLit=_isLiteral(val);if(isId){msg=`<${tag}> 'id' should be prefixed as ':id'${isExpr?"":" and set to an expression"}`;mid=0}else if(!isExpr){msg=`<${tag}> ':id' should be set to an expression`;mid=1}if(msg){_emitIssue(ruleCtx,msg,idAttr,mid)}if(isExpr&&isLit){msg=`<${tag}> '${idAttr}' attribute expression returns a constant - convert to a calculated expression`;_emitIssue(ruleCtx,msg,idAttr,2)}}};function _emitIssue(ruleCtx,msg,idAttr,mid){var issue,attrPos;issue=new ruleCtx.Issue(msg);attrPos=ruleCtx.utils.DomUtils.getAttribPosition(ruleCtx.data,ruleCtx.node,idAttr);issue.setPosition(attrPos.row,attrPos.col,attrPos.start,attrPos.end);if(mid){issue.setMsgKey(RULE_NAME+"_"+mid)}ruleCtx.reporter.addIssue(issue,ruleCtx)}function _isAttrExpr(s){var rc=false;if(typeof s==="string"){s=s.trim();rc=s.startsWith("[[")||s.startsWith("{{")}return rc};function _stripExprDelims(s){return s.substring(2,s.length-2).trim()}function _isLiteral(s){return s.charAt(0)==="'"&&s.charAt(s.length-1)==="'"};module.exports=Rule;