const parser=require("fast-xml-parser"),{readFile:readFile,readDir:readDir,stat:stat,isPrefabProject:isPrefabProject,getWmProjectPropertiesFilePath:getWmProjectPropertiesFilePath,getThemesConfigPropertiesFilePath:getThemesConfigPropertiesFilePath,getAuthInfoFilePath:getAuthInfoFilePath,getSecurityConfigPath:getSecurityConfigPath,getLayoutsConfigPath:getLayoutsConfigPath,getPagesConfigPath:getPagesConfigPath,getPrefabsDirPath:getPrefabsDirPath,getPrefabPagesDirPath:getPrefabPagesDirPath,getPrefabConfigPath:getPrefabConfigPath,getWmProjectPropertiesFromTargetPath:getWmProjectPropertiesFromTargetPath}=require("./wm-utils"),{join:join}=require("path"),getWmProjectProperties=async e=>{let t=await readFile(getWmProjectPropertiesFilePath(e),"utf8");const r={};return parser.parse(t,{textNodeName:"text",ignoreAttributes:!1,ignoreNameSpace:!1,allowBooleanAttributes:!1,parseNodeValue:!0,parseAttributeValue:!1,trimValues:!0,parseTrueNumberOnly:!1,arrayMode:!1,stopNodes:["parse-me-as-string"]},!0).properties.entry.forEach(e=>r[e["@_key"]]=e.text?e.text:""),r},getWmProjectPropertiesFromTarget=async e=>{return await readFile(getWmProjectPropertiesFromTargetPath(),"utf8")},getThemesConfigProperties=async e=>{const t=await readFile(getThemesConfigPropertiesFilePath(e),"utf8");return JSON.parse(t)},getSecurityConfig=async e=>stat(getAuthInfoFilePath(e)).then(()=>new Promise(async(t,r)=>{let a=null;JSON.parse(await readFile(getAuthInfoFilePath(e))).enforceSecurity&&(a=JSON.parse(await readFile(getSecurityConfigPath(e),"utf8"))),t(a)}),()=>Promise.resolve(null)),getLayoutsConfig=async e=>{let t=await readFile(getLayoutsConfigPath(e),"utf8");return t=JSON.parse(t)},getPagesConfig=async e=>{let t=await readFile(getPagesConfigPath(e),"utf8");return t=JSON.parse(t)},getPrefabPartialsConfig=async(e,t)=>{let r=await readFile(`${getPrefabPagesDirPath(e,t)}/pages-config.json`,"utf8");return r=JSON.parse(r).filter(e=>"partial"===e.type.toLowerCase()||"template"===e.type.toLowerCase()).map(e=>({...e,prefabName:t}))},getPrefabConfigsUsedInApp=async(e,t)=>{const r=new Map,a=getPrefabsDirPath(t);return stat(a).then(()=>new Promise(async(i,o)=>{for(const e of await readDir(a))(await stat(join(a,e))).isDirectory()&&r.set(e,await readFile(getPrefabConfigPath(t,e)));isPrefabProject(e)&&r.set("__self__",await readFile(`${t}/src/main/webapp/config.json`)),i(r)}),()=>Promise.resolve(r))};module.exports={getWmProjectProperties:getWmProjectProperties,getWmProjectPropertiesFromTarget:getWmProjectPropertiesFromTarget,getThemesConfigProperties:getThemesConfigProperties,getSecurityConfig:getSecurityConfig,getLayoutsConfig:getLayoutsConfig,getPagesConfig:getPagesConfig,getPrefabConfigsUsedInApp:getPrefabConfigsUsedInApp,getPrefabPartialsConfig:getPrefabPartialsConfig};