/*
 * Copyright (c) 2018, 2026, 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-avatar-aria-role";const ROLE="role";const ARIA_LABEL="aria-label";const ARIA_LABELLEDBY="aria-labelledby";const DATABIND="data-bind";function getName(){return RULE_NAME};function getShortDescription(){return"<oj-avatar> and <oj-c-avatar> must have an 'aria-label' or 'aria-labelledby' attribute if role=\"img\" has been specified"};function getDescription(){return"For accessibility, <oj-avatar> and <oj-c-avatar> must have an <i>'aria-label'</i> or </i>'aria-labelledby'</i> attribute if <i>role='img'</i> has been specified"};function register(){return{"<oj-avatar>":_onTag,"<oj-c-avatar>":_onTag}};function _onTag(ruleCtx,tagName){var attribs,attrib,hasLabel,attr;var DomUtils=ruleCtx.utils.DomUtils;if(!DomUtils.hasAttrib(ruleCtx.node,ROLE)||DomUtils.getAttribValue(ruleCtx.node,ROLE)!=="img"){return}attribs=ruleCtx.node.attribs;if(_hasAttrib(attribs,DATABIND)){attrib=attribs["data-bind"];attr=DomUtils.extractAttribsFromDataBind(attrib);if(attr){hasLabel=attr[ARIA_LABEL]||attr[ARIA_LABELLEDBY]}}else{hasLabel=_hasAttrib(attribs,ARIA_LABEL)||_hasAttrib(attribs,ARIA_LABELLEDBY)}if(!hasLabel){var issue,attrPos;issue=new ruleCtx.Issue(`'role' attribute of 'img' specified on <${tagName}>, but 'aria-label' or 'aria-labelledby' is missing`);attrPos=DomUtils.getAttribPosition(ruleCtx.data,ruleCtx.node,"role");issue.setPosition(attrPos.row,attrPos.col,attrPos.start,attrPos.end);ruleCtx.reporter.addIssue(issue,ruleCtx)}};function _hasAttrib(attribs,attrName){var attrib,ret=false;for(attrib in attribs){attrib=attrib.charAt(0)===":"?attrib.substr(1):attrib;if(attrib===attrName){ret=true;break}}return ret};module.exports={getName,getDescription,getShortDescription,register};