/*
 * 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/
 */
module.exports=function(ruleCtx,tagName,theme){var id,issue,label,elem,ledge,ret;var labelHint,hasLabelOrAriaLabel;id=_getAttrib(ruleCtx,"id");if(!id){id=_getDataBindIdAttr(ruleCtx)}if(id){if(_isExpression(id)){return null}elem=_searchPageForFor(ruleCtx,id,-1);if(elem){if(elem.name==="label"){issue=new ruleCtx.Issue(`Accessibility: <${tagName}> 'id' attribute \"${id}\" has matching <label> - <oj-label> preferred`);issue.setMsgKey(ruleCtx.ruleName+"_1");_updateAttrPos(ruleCtx,issue,"id");ret=_addIssue(ret,issue.setSeverity("info"))}return ret}}if(_getAttrib(ruleCtx,"label-hint")){labelHint=true;ledge=_getAttrib(ruleCtx,"label-edge");if(!ledge&&theme!=="none"){ledge=theme==="Redwood"||theme==="Stable"?"inside":"provided"}if(ledge==="none"){hasLabelOrAriaLabel=true}else if(ledge==="inside"){hasLabelOrAriaLabel=true}else if(_isExpression(ledge)){return}else{let form=ruleCtx.utils.DomUtils.isChildOfElemNode("oj-form-layout",ruleCtx.node);if(form){if(ledge!=="none"){hasLabelOrAriaLabel=true}}}if(hasLabelOrAriaLabel){return}}label=_getAttrib(ruleCtx,"aria-label");if(!label){label=_getAttrib(ruleCtx,"aria-labelledby");if(label){return}if(id){if(_forAttrsExpressions(ruleCtx)){issue=new ruleCtx.Issue(`Accessibility: ${tagName}> 'id' attribute \"${id}\" may have no matching <oj-label> - check <oj-label> \"for\" expressions`);_updateAttrPos(ruleCtx,issue,"id");issue.setMsgKey(ruleCtx.ruleName+"_2");issue.setSeverity("info")}else{if(labelHint){issue=new ruleCtx.Issue(`Accessibility: <${tagName}> : 'id' attribute \"${id}\"  has no matching <oj-label>, 'id' or 'aria-label attribute. 'label-edge' is '${ledge}' (theme: '${theme}')`);issue.setMsgKey(ruleCtx.ruleName+"_5")}else{issue=new ruleCtx.Issue(`Accessibility: <${tagName}> 'id' attribute \"${id}\" has no matching <oj-label> or 'aria-label'.  Set 'label-hint', or associate an 'oj-label'.`);issue.setMsgKey(ruleCtx.ruleName+"_3")}_updateAttrPos(ruleCtx,issue,"id")}}else{if(labelHint){issue=new ruleCtx.Issue(`Accessibility: <${tagName}> : has no 'id' or 'aria-label attribute.  'label-edge' is '${ledge}' (theme: '${theme}')`);issue.setMsgKey(ruleCtx.ruleName+"_6")}else{issue=new ruleCtx.Issue(`Accessibility: <${tagName}> : has no 'id' or 'aria-label attribute!`);issue.setMsgKey(ruleCtx.ruleName+"_4")}}}if(issue){return _addIssue(ret,issue)}};function _getAttrib(ruleCtx,attr){return _getNodeAttrib(ruleCtx,ruleCtx.node,attr)};function _getNodeAttrib(ruleCtx,node,attr){var du=ruleCtx.utils.DomUtils;return du.getAttribValue(node,attr)||du.getAttribValue(node,":"+attr)};function _searchPageForFor(ruleCtx,id){var tags,node,attribs,attrib,lcattr,o,i;tags=ruleCtx.utils.DomUtils.getElemsByName(["oj-label","label"]);if(tags){for(i=0;i<tags.length;i++){node=tags[i];attribs=node.attribs;if(attribs){for(attrib in attribs){lcattr=attrib.toLowerCase();if((lcattr==="for"||lcattr===":for")&&attribs[attrib]===id){return node}else{o=_getDataBindForAttr(ruleCtx,node);if(o===id){return node}}}}}}return null};function _getDataBindIdAttr(ruleCtx){var o=ruleCtx.utils.DomUtils.getDataBindAttrs(ruleCtx);return o&&o["id"]};function _getDataBindForAttr(ruleCtx,node){var o=ruleCtx.utils.DomUtils.getDataBindAttrsFromNode(ruleCtx,node);return o&&o["for"]};function _forAttrsExpressions(ruleCtx){var forAttrs,ret=false,i;forAttrs=_getLabelForValues(ruleCtx);for(i=0;i<forAttrs.length;i++){if(_isExpression(forAttrs[i])){ret=true;break}}return ret};function _getLabelForValues(ruleCtx){var forAttrs=[],tags,node,attribs,attrib,i;tags=ruleCtx.utils.DomUtils.getElemsByName(["oj-label","label"]);if(tags){for(i=0;i<tags.length;i++){node=tags[i];attribs=node.attribs;if(attribs){for(attrib in attribs){if(attrib.toLowerCase()==="for"||attrib.toLowerCase()===":for"){forAttrs.push(attribs[attrib])}else{if(_getDataBindForAttr(ruleCtx,node)){forAttrs.push(attribs[attrib])}}}}}}return forAttrs};function _isExpression(s){return /[\[\]\(\}\{+*\/]/.test(s)};function _addIssue(ret,issue){ret=ret||[];ret.push(issue);return ret};function _updateAttrPos(ruleCtx,issue,attrName){var attrPos=ruleCtx.utils.DomUtils.getAttribPosition(ruleCtx.data,ruleCtx.node,attrName);issue.setPosition(attrPos.row,attrPos.col,attrPos.start,attrPos.end)};