/*
 * 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-acc-aria-labelledby";const ARIA_LABELLEDBY="aria-labelledby";const DATABIND="data-bind";const DESCRIPTION="The <i>'aria-labelledby'</i> attribute contains the element id of another element to provide a relationship between an object and its label. The label ID can be provided by an 'id' or a JET 'label-id' attribute. e.g. <p><oj-label id=\"groupReadonly\" label-id=\"groupReadonly\" class=\"oj-label\">Read Only switches</oj-label><br><oj-switch id=\"switch-1\" readonly aria-labelledby=\"groupReadonly\"></oj-switch><br>";function getName(){return RULE_NAME};function getShortDescription(){return"JET 'aria-labelledby' attribute must refer to an element 'id' or 'label-id' attribute"};function getDescription(){return DESCRIPTION};function register(){return{"webcomp":_onComp}};function _onComp(ruleCtx){var attrs,attr,val;if(!(attrs=ruleCtx.tagNode.attribs)){return}for(attr in attrs){val=attrs[attr];_onAttr(ruleCtx,attr,val)}}function _onAttr(ruleCtx,attrName,attrValue){var attr,node,attrOrig=attrName;var ids,i;if(attrName===DATABIND){attr=ruleCtx.utils.DomUtils.extractAttribsFromDataBind(attrValue);if(attr&&attr[ARIA_LABELLEDBY]){attrName=ARIA_LABELLEDBY;attrValue=attr[ARIA_LABELLEDBY]}}if(attrName!==ARIA_LABELLEDBY||_isExpression(attrValue)){return}ids=attrValue.split(" ");for(i=0;i<ids.length;i++){ids[i]=ids[i].trim();if(ids.length){if(_isExpression(ids[i])){continue}node=ruleCtx.utils.DomUtils.getElemById(ids[i],true);if(!node){let issue=new ruleCtx.Issue(`<${ruleCtx.tagNode.name}> 'aria-labelledby' attribute '${ids[i]}' has no matching element with same id`);_addIssue(ruleCtx,issue,attrOrig)}}}};function _addIssue(ruleCtx,issue,attrName){let attrPos=ruleCtx.utils.DomUtils.getAttribPosition(ruleCtx.data,ruleCtx.node,attrName);issue.setPosition(attrPos.row,attrPos.col,attrPos.start,attrPos.end);ruleCtx.reporter.addIssue(issue,ruleCtx)};function _isExpression(s){return /[(}{}+*\/]/.test(s)};module.exports={getName,getDescription,getShortDescription,register};