/*
 * 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 path=require("path");const Utils=require("../jetwc-lib/jetwcutils-componentAuditUtils");const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-subproperty-writeback"};ruleDef.prototype.getShortDescription=function(){return"Check for direct sub-property binding to writeback properties in HTML"};ruleDef.prototype.getDescription=function(){return"Detects cases where a sub-property is directly bound to a write-back property in the component HTML e.g <oj-input-text value='{{$properties.obj.somevalue}}'>. This will bypass the correct change notification mechanisms and could lead to bugs as a release"};ruleDef.prototype.register=function(context){return{attrexpr:this._doAudit}};ruleDef.prototype._doAudit=function(context,attribute,attributeValue){let issue;const candidateRE=/^\{\{\$properties\.(\w*)\.[\w\.]*\}\}$/i;const checkProperty=attributeValue.match(candidateRE);if(checkProperty&&checkProperty.length===2){const componentName=Utils.matchComponentPath(context,path.dirname(context.filepath));if(componentName){const meta=Utils.componentInfo(context,componentName);if(meta.properties[checkProperty[1]]){if(meta.properties[checkProperty[1]].writeback){issue=new context.Issue(`Complex Properties such as the expression ${attributeValue} in the component ${componentName} should not be bound directly for writeback`);context.reporter.addIssue(issue,context)}}else{issue=new context.Issue(`Property '${checkProperty[1]}' used in the expression ${attributeValue} is not a valid property for the component ${componentName}`);context.reporter.addIssue(issue,context)}}}};module.exports=ruleDef;