/*
 * 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 RULE_NAME="oj-html-file-pick-accept";const DESCRIPTION="Valid array entries for the 'accept' attribute of <oj-file-picker> are:<p>"+"1) a file suffix beginning with a period, e.g. \".xxx\"<br>"+"2) an empty string<br>"+"3) an audio, video, or image file, e.g. \"image/*\" or \"audio/*\", or \"video/*\".";const SHORT_DESCRIPTION="Array entries for <oj-file-picker accept=' ...'> attribute should be valid file strings.";const BASE_MSG="<oj-file-picker> attribute 'accept'";const FILE_PICKER="oj-file-picker";const ACCEPT="accept";const RO_EXPR="[[";const RW_EXPR="{{";const ARRAY_LEFT="[";const ARRAY_RIGHT="]";const GOOD_VALS=[".","audio/","video/","image/"];class Rule{getName(){return RULE_NAME}getDescription(){return DESCRIPTION}getShortDescription(){return SHORT_DESCRIPTION}register(){return{"<oj-file-picker>":this._onTag}}_onTag(ruleCtx){let accept;accept=ruleCtx.tagNode.attribs;accept=accept?accept[ACCEPT]:null;if(accept){let avals=this._checkAttr(ruleCtx,accept);if(avals){this._checkArray(ruleCtx,avals)}}}_emitIssue(ruleCtx,msgNum,info,val){var msg,issue;switch(msgNum){case 0:msg=`${BASE_MSG} is not an array of strings`;break;case 1:msg=`${BASE_MSG} syntax : ${info.msg} at index ${info.startIndex}`;break;case 2:msg=`${BASE_MSG} : invalid array entry \"${val}\"`;break}if(msg){issue=new ruleCtx.Issue(msg);if(msgNum){issue.setMsgKey(RULE_NAME+"_"+msgNum)}let pos=ruleCtx.utils.DomUtils.getAttribPosition(ruleCtx.data,ruleCtx.node,ACCEPT);issue.setPosition(pos.row,pos.col,pos.start,pos.end);ruleCtx.reporter.addIssue(issue,ruleCtx)}}_checkArray(ruleCtx,avals){var v,i,j;for(i=0;i<avals.length;i++){v=avals[i];if(typeof v!=="string"){this._emitIssue(ruleCtx,2,null,v);continue}for(j=0;j<GOOD_VALS.length;j++){if(v.startsWith(GOOD_VALS[j])||v===""){break}}if(j>=GOOD_VALS.length){this._emitIssue(ruleCtx,2,i,v)}}}_checkAttr(ruleCtx,s){if(s.startsWith(RO_EXPR)||s.startsWith(RW_EXPR)){return}if(s.charAt(0)!==ARRAY_LEFT&&s.charAt(s.length-1)!==ARRAY_RIGHT){this._emitIssue(ruleCtx,0);return}let o=ruleCtx.utils.utils.parseJson(s,false);if(o.msg){this._emitIssue(ruleCtx,1,o);return}return o.obj}}module.exports=Rule;