/*
 * 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 RULENAME="oj-html-template-index";const DESCRIPTION="Due to a bug in JET 9.x <oj-list-view>, the value of ItemTemplateContext.index starts at 1 instead "+"of 0, depending on whether skeletons (when a fetch from a DataProvider "+"takes more than 50ms) are displayed or not. In JET 10.0.0, the index value always starts at 0 as intended. ";"Review use of the index value to ensure correct usage.";const SHORT_DESCRIPTION="Due to a bug in JET 9.x <oj-list-view>, the value of ItemTemplateContext.index starts at 1 instead "+"of 0, depending on whether skeletons are displayed or not.";const OJ_LIST_VIEW="oj-list-view";const DATA_OJ_AS="data-oj-as";const $CURINDEX="$current.index";const DOT_INDEX=".index";const TAG="tag";const RO_EXPR="[[";const RW_EXPR="{{";class Rule{getName(){return RULENAME}getDescription(){return DESCRIPTION}getShortDescription(){return SHORT_DESCRIPTION}register(regCtx){this._utils=regCtx.utils.utils;return{"<template>":this._onTemplate}}_onTemplate(ruleCtx){if(this._childOfListView(ruleCtx)){let val;if(val=ruleCtx.utils.DomUtils.getAttribValue(ruleCtx.node,DATA_OJ_AS)){this._processTemplateAttribs(ruleCtx,val)}}}_processTemplateAttribs(ruleCtx,find){var node;var find=find+DOT_INDEX;node=ruleCtx.node;this._processDescendants(ruleCtx,node,find)}_processDescendants(ruleCtx,node,find){var nodes,n,attrs,attr,val;nodes=node.children;if(!nodes){return}for(n in nodes){n=nodes[n];if(!n.type||n.type!==TAG){continue}attrs=n.attribs;if(attrs&&this._utils.hasAnyProps(attrs)){for(attr in attrs){val=attrs[attr];if(_isExpr(val)){if(val.includes(find)||val.includes($CURINDEX)){let issue=new ruleCtx.Issue(`Behavior change to ItemTemplateContext.index : <${n.name} ${attr}= >`);let attrPos=ruleCtx.utils.DomUtils.getAttribPosition(ruleCtx.data,n,attr);issue.setPosition(attrPos.row,attrPos.col,attrPos.start,attrPos.end);ruleCtx.reporter.addIssue(issue,ruleCtx)}}}}if(n.children){this._processDescendants(ruleCtx,n,find)}}}_childOfListView(ruleCtx){let stack=ruleCtx.elemStack;for(let i=stack.length-1;i>=0;i--){if(stack[i].name===OJ_LIST_VIEW){return true}}return false}}function _isExpr(s){return s.startsWith(RO_EXPR)||s.startsWith(RW_EXPR)};module.exports=Rule;