/*
 * 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 RULENAME="oj-html-msgs-cat-text";const DESCRIPTION="For theme 'Redwood', the UX specification for Messages does not include category text."+"By default, the component renders the category text based on the severity. Redwood themed "+"applications should explicitly set the 'display-options.category' attribute to 'none' so "+"that the category text will not be rendered, and messages will match the UX "+"specificatiopn.";const SHORT_DESCRIPTION="Redwood themed applications should explicitly set the 'display-options.category' attribute to 'none'";const DISP_OPTS_CATEGORY="display-options.category";const OJ_MESSAGE="oj-message";class Rule{getName(){return RULENAME}getDescription(){return DESCRIPTION}getShortDescription(){return SHORT_DESCRIPTION}register(){return{"<oj-messages>":this._onOjMessages}}_onOjMessages(ruleCtx){var msgs,val;var node=ruleCtx.tagNode;var attribs=node.attribs;var attr=attribs[DISP_OPTS_CATEGORY];var template=_hasMessageTemplate(node);if(template){if(msgs=_getMessages(template)){msgs.forEach(msg=>{val=undefined;if(msg.attribs){if((val=msg.attribs[DISP_OPTS_CATEGORY])!==undefined){if(val==="none"||val!=="auto"&&val!=="header"){return}}}this._emitIssue(ruleCtx,val!==undefined?1:2,msg,val)})}else{this._emitIssue(ruleCtx,3)}}else{if(attr!=="none"){this._emitIssue(ruleCtx,4,node,attr)}}}_emitIssue(ruleCtx,id,node,val){var issue;switch(id){case 1:issue=new ruleCtx.Issue(`<oj-message> attrib 'display-options.category' set to '${val}' - expected 'none'`);break;case 2:issue=new ruleCtx.Issue(`<oj-message> attrib 'display-options.category' missing or not set to 'none'`);break;case 3:issue=new ruleCtx.Issue("<template> with <oj-message> children expected");break;case 4:issue=new ruleCtx.Issue(`<oj-messages> attrib 'display-options.category' missing or not set to 'none'`);break}if((id===1||id===4)&&val){let attrPos=ruleCtx.utils.DomUtils.getAttribPosition(ruleCtx.data,node,DISP_OPTS_CATEGORY);issue.setPosition(attrPos.row,attrPos.col,attrPos.start,attrPos.end)}else if(id===2){issue.setPosition(null,null,node.startIndex,node.startIndex+OJ_MESSAGE.length)}if(id>1){issue.setMsgKey(RULENAME+"_"+(id-1))}ruleCtx.reporter.addIssue(issue,ruleCtx)}};function _hasMessageTemplate(node){var ch,n,i;if((ch=node.children)&&ch.length){for(i=0;i<ch.length;i++){n=ch[i];if(n.type==="tag"&&n.name==="template"){if(n.attribs&&n.attribs.slot==="messageTemplate"){return n}}}}return null};function _getMessages(node){var ch,msgs=null;if((ch=node.children)&&ch.length){ch.forEach(n=>{if(n.type==="tag"&&n.name==="oj-message"){if(!msgs){msgs=[]}msgs.push(n)}})}return msgs};module.exports=Rule;