/*
 * 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-form-maxcols";const DESCRIPTION="Prior to JET 10.0.0, maxColumns in 'row' direction was not responsive, so that the "+"number of columns was exactly equal to maxColumns. In JET 10.0.0 and later, maxColumns "+"<b>is</b> responsive, so that the actual number of columns may now be less, depending on the "+"space available to the form.<br>If the app needs to preserve the old fixed-columns behavior, "+"then it should remove any 'max-columns' attribute (which is deprecated in dynamic UI 10.0.0) "+"from <oj-dynamic-form>, and set the new 'columns' property in the layout.";const SHORT_DESCRIPTION="The 'max-columns' attribute for <oj-dynamic-form>, or the 'maxColumns' property for layout, may have a behavioral change in JET 10.0.0.";var path;const LAYOUT_JSON="layout.json";const FORM="form";const LAYOUTS="layouts";const MAX_COLUMNS="max-columns";const COLUMN="column";const DIRECTION="direction";const ID="id";const SEV_CRITICAL="critical";const ISSUE="<@tag@id> with 'max-columns' may have a behavior change in JET 10.0.0.";class Rule{getName(){return RULE_NAME}getDescription(){return DESCRIPTION}getShortDescription(){return SHORT_DESCRIPTION}register(){path=require("path");return{"json":this._onJson,"<oj-dynamic-form>":this._onTag}}_onJson(ruleCtx){var json,layouts,name,obj,layouts,layout,olayouts,issue,pos;if(path.basename(ruleCtx.filepath)!==LAYOUT_JSON){return}json=ruleCtx.suppData.obj;if(ruleCtx.suppData.msg){if(!ruleCtx.rulePack.isRuleEnabled("oj-json-syntax","JET")){issue=new ruleCtx.Issue(ruleCtx.suppData.msg);issue.setPosition(ruleCtx.suppData.line,ruleCtx.suppData.col,ruleCtx.suppData.position,ruleCtx.suppData.position+3);issue.setMsgKey(RULE_NAME+"_2");issue.setSeverity(SEV_CRITICAL);ruleCtx.reporter.addIssue(issue,ruleCtx);return}}if(!(layouts=json.layouts)){return}for(name in layouts){obj=layouts[name];if(obj.layoutType!==FORM){continue}if(!(olayouts=obj.layouts)){continue}for(layout in olayouts){obj=olayouts[layout];if(obj.layoutType===FORM&&obj.layout){if(obj.layout.maxColumns>1){if(!obj.layout.columns||obj.layout.direction!==COLUMN){issue=new ruleCtx.Issue(`layout '${name}' : '${layout}' with maxColumns may have behavior change in JET 10.0.x.`);if(pos=_getPos(ruleCtx.suppData.ast,name,layout)){issue.setPosition(pos.row,pos.col,pos.start,pos.end)}issue.setMsgKey(RULE_NAME+"_1");ruleCtx.reporter.addIssue(issue,ruleCtx)}}}}}}_onTag(ruleCtx,tag){if(_isGT(_getTagAttr(ruleCtx,MAX_COLUMNS),1)&&_getTagAttr(ruleCtx,DIRECTION)!==COLUMN){let id=_getTagAttr(ruleCtx,ID);id=id?" id='"+id+"'":"";let msg=ISSUE.replace("@tag",tag).replace("@id",id);let issue=new ruleCtx.Issue(msg);let pos=ruleCtx.utils.DomUtils.getAttribPosition(ruleCtx.data,ruleCtx.node,MAX_COLUMNS);issue.setPosition(pos.row,pos.col,pos.start,pos.end);ruleCtx.reporter.addIssue(issue,ruleCtx)}}}function _getLayout(member,name,layoutName){var layouts,mems,mem,lo,ar,i,j,k;layouts=member.value.members;for(i=0;i<layouts.length;i++){if(layouts[i].name===name){lo=layouts[i];if(lo.value&&lo.value.type==="Object"){mems=lo.value.members;if(mems){for(j=0;j<mems.length;j++){mem=mems[j];if(mem.name===LAYOUTS){if(mem.value.type==="Object"){ar=mem.value.members;for(k=0;k<ar.length;k++){if(ar[k].name===layoutName){return ar[k]}}}}}}}}}};function _getPos(ast,name,layoutName){var members,member,layout,mems,pos,i,j;members=ast.members;for(i=0;i<members.length;i++){member=members[i];if(member.name===LAYOUTS&&member.value){if(layout=_getLayout(member,name,layoutName)){if(layout&&layout.value&&layout.value.type==="Object"){mems=layout.value.members;for(j=0;j<mems.length;j++){if(mems[j].name==="layout"){pos=mems[j].pos;return{row:pos.row,col:pos.col,start:pos.index,end:pos.index+layoutName.length}}}}}}}return null};function _getTagAttr(ruleCtx,attr){var attrs=ruleCtx.tagNode.attribs;return attrs?attrs[attr]:null}function _isGT(val,n){val=parseInt(val);return!isNaN(val)&&val>n}module.exports=Rule;