"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.checkPageJSON=checkPageJSON;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),locales_1=tslib_1.__importDefault(require("../../../../../utils/locales/locales")),common_1=require("../common"),schemaValidate_1=require("../../validate/schemaValidate"),tools_1=require("../../../../../utils/tools"),common_2=require("../../../../../utils/common"),theme_1=require("../theme"),checkHexColor=e=>{const{inputJSON:a,mode:o,pagePath:t,themeLocation:r}=e;let i=t+".json";if(a){r&&(i=`${t}.json or ${r}["${o}"]`);const{navigationBarBackgroundColor:e,backgroundColor:l}=a;void 0===e||(0,tools_1.isHexColor)(e)||(0,common_2.throwError)({msg:`["navigationBarBackgroundColor"]: "${e}" is not hexColor`,filePath:i}),void 0===l||(0,tools_1.isHexColor)(l)||(0,common_2.throwError)({msg:`["backgroundColor"]: "${l}" is not hexColor`,filePath:i})}};function checkPageJSON(e,a){const{pagePath:o,miniprogramRoot:t=""}=a,r=(0,tools_1.normalizePath)(path_1.default.posix.join(t,o+".json"));if(!e.stat("",r))return{};const i=e.getFile("",r),l=(0,common_1.checkJSONFormat)((0,common_2.checkUTF8)(i,r),r),n=(0,theme_1.getThemeLocation)(e);if(!n){const e=(0,common_1.getPageJSONVariableDecalearProperty)(l);e.length&&(0,common_2.throwError)({msg:'["themeLocation"] is required because:\n'+e.map(e=>`"${e.value}" as variable was declared at ${r}:${e.property}`).join("\n"),filePath:r})}let c={light:{},dark:{}};n&&(c=(0,theme_1.checkThemeJSON)(e,{themeLocation:n}));const m=(0,theme_1.mergeThemeJSONToPageJSON)(c,l,r),s=(0,schemaValidate_1.schemaValidate)("page",m.pageJSONLight),h=(0,schemaValidate_1.schemaValidate)("page",m.pageJSONDark),g=(0,common_1.getPageJSONVariableDecalearProperty)(m.pageJSONLight);g.length&&(0,common_2.throwError)({msg:g.map(e=>`"${e.value}" as variable was declared at ${r}:${e.property}, but not found at ${n}["light"]`).join("\n"),filePath:r});const _=(0,common_1.getPageJSONVariableDecalearProperty)(m.pageJSONDark);return _.length&&(0,common_2.throwError)({msg:_.map(e=>`"${e.value}" as variable was declared at ${r}:${e.property}, but not found at ${n}["dark"]`).join("\n"),filePath:r}),s.warning&&(l.__warning__=locales_1.default.config.INVALID.format(s.warning)),n&&h.warning&&(l.__warning__=locales_1.default.config.INVALID.format(h.warning)),(0,schemaValidate_1.transValidateResult)(n?`${r} or ${n}["light"]`:r,s),n&&(0,schemaValidate_1.transValidateResult)(`${r} or ${n}["dark"]`,h),checkHexColor({inputJSON:m.pageJSONLight,mode:"light",themeLocation:n||"",filePath:r,pagePath:o}),checkHexColor({inputJSON:m.pageJSONDark,mode:"dark",themeLocation:n||"",filePath:r,pagePath:o}),l}