/*
 * 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 PACK_PATH="node_modules/@oracle/oraclejet-core-pack/oj-c/metadata";const ALLCOMP_JSON="allComponents.json";const LOAD_MSG="Loading JET Core Pack (oj-c)...";const LOAD_AMD_MSG="Using AMD JET Core Pack (oj-c)...";const BOOLEAN="boolean";function Ojc(isOJet,isAMD,cwd,msgCtx,nd,fsUtils){this._isOJet=!!isOJet;this._isAMD=isAMD;this._nd=nd;this._cwd=cwd.replace(/\\/g,"/");this._fsUtils=fsUtils;this._msgCtx=msgCtx;this._fp=undefined;this._components=null;this._version=null}Ojc.prototype.getComponents=function(){return this._components};Ojc.prototype.getPackVersion=function(){return this._version};Ojc.prototype.setPath=function(fp){if(!this._isAMD){if(fp&&this._fsUtils.getFileType(fp)==="d"){fp=this._nd.path.join(fp,ALLCOMP_JSON)}else if(typeof fp===BOOLEAN){fp=null}}this._fp=fp};Ojc.prototype.load=function(){var o,comps,comp,isPath,info=this._msgCtx.info;if(this._components){return this._components}if(!this._isAMD){if(this._fp===null){return this._components};if(this._fp===undefined){this._fp=this._nd.path.join(this._cwd,PACK_PATH,ALLCOMP_JSON)}else{isPath=true}if(!this._fsUtils.fileExists(this._fp)){let m=`Jet Core Pack metadata not found at '${this._fp}' [JAF-9015]\n`;let fn=isPath?this._msgCtx.error:this._msgCtx.warn;fn(m);return}info(LOAD_MSG);if(!(o=this._fsUtils.readJsonSync(this._fp,false,false))){this._msgCtx.error("Failed to read oj-c core pack allComponents.json");return false}else if(typeof o==="string"){this._msgCtx.error(o);return}comps=o.components;this._version=o.version}else{info(LOAD_AMD_MSG);comps=this._fp;if(comps.version){if(comps.name!=="oj-c"){this._msgCtx.error(`Expected JET oj-c Core Pack allComponents.json - received pack named ${comps.name}'`);return false}this._version=comps.version;comps=comps.components}else{this._version="supplied, version not available"}}if(comps){let n=0;for(comp in comps){n++;if(!this._components){this._components={}}this._components[comp]=comps[comp]}info(`... ${n} JET Core Pack components loaded`)}return this._components};module.exports=Ojc;