/*
 * 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 fs=require("fs");const path=require("path");const META_DIR=path.join(__dirname,"../meta");const META_FILE="jetauditmeta.js";function show(nd,fsUtils){var meta,delHist,renHist;meta=_getMetaData(nd,fsUtils);if(!meta){return}delHist=meta.delMeta;renHist=meta.renMeta;_showTagDeletes(delHist);_showRenames(renHist);_showDeletes(delHist)};function _showTagDeletes(delHist){var tags,tag;tags=delHist.tags;if(!tags){return}var line="-".repeat(36);console.log("\n"+line);console.log("         Deleted Web Components       ");console.log(line+"\n");for(tag in tags){console.log(tag)}};function _showRenames(o){var line="-".repeat(35);console.log("\n"+line);console.log("         Renamed Classes            ");console.log(line+"\n");var len=_longest(o);for(let n in o){console.log(`${_ljust(n,len)} -> ${o[n].to} (${o[n].since})`)}console.log("\n")};function _showDeletes(o){var clazzes,clazz,ce,line,len;if(o.classes){line="-".repeat(36);console.log("\n"+line);console.log("         Deleted Classes            ");console.log(line+"\n");len=_longest(o.classes);clazzes=o.classes;for(clazz in clazzes){console.log(`${_ljust(clazz,len)}  (${clazzes[clazz]})`)}}line="-".repeat(45);console.log("\n"+line);console.log("         Deleted Methods & Members           ");console.log(line);len=_longest(o);for(clazz in o){let meths,mems,meth,mem;if(clazz==="classes"||clazz==="tags"){continue}ce=o[clazz];console.log("\n"+clazz);if(ce.methods){meths=ce.methods;len=_longest(meths)+2;for(meth in meths){console.log(`   ${_ljust(meth+"()",len)}  (${meths[meth]})`)}}if(ce.members){mems=ce.members;len=_longest(mems);for(mem in mems){console.log(`   ${_ljust(mem,len)}  (${mems[mem]})`)}}}console.log("\n")};function _ljust(s,n){var len=n-s.length>=0?n-s.length:0;return s+" ".repeat(len)}function _longest(o){var len=0;for(let n in o){if(n!=="classes"&&n!=="tags"){len=n.length>len?n.length:len}}return len};function _getMetaData(nd,fsUtils){var jetVers,metaVer,metaFile,meta;jetVers=_getVersionList(nd,fsUtils);if(!jetVers||!jetVers.length){return}metaVer=jetVers[jetVers.length-1];metaFile=path.join(META_DIR,metaVer,META_FILE);try{meta=nd.metaLoader.loadMeta(metaFile,nd,fsUtils)}catch(e){meta=null;this._error("Metadata '"+metaFile+"' not found!")}return meta};function _getVersionList(nd,fsUtils){var verList=[];var files,inFile,ftype,i;try{files=fs.readdirSync(META_DIR);for(i=0;i<files.length;i++){inFile=files[i];ftype=fsUtils.getFileTypeSync(path.join(META_DIR,inFile));if(ftype==="d"){verList.push(inFile)}else if(ftype instanceof Error){throw ftype}}}catch(e){console.log(e.message)}if(verList&&verList.length){verList.sort(function(a,b){var va=a.split(".");var vb=b.split(".");va.forEach(function(v,i,a){a[i]=parseInt(v)});vb.forEach(function(v,i,a){a[i]=parseInt(v)});if(va[0]>vb[0]){return 1}if(va[0]<vb[0]){return-1}if(va[1]>vb[1]){return 1}if(va[1]<vb[1]){return-1}if(va[2]>vb[2]){return 1}if(va[2]<vb[2]){return-1}return 0})}return verList};module.exports.show=show;