"use strict";function getEmailTemplatesPath(){const e=[path_1.default.resolve(process.cwd(),"backend","email","templates"),path_1.default.resolve(__dirname,"../../../email","templates"),path_1.default.resolve(process.cwd(),"email","templates"),path_1.default.resolve(__dirname,"../../email","templates")];for(const t of e)if(fs_1.default.existsSync(t)){console_1.logger.debug("EMAIL",`Templates directory found at: ${t}`);return t}console_1.logger.warn("EMAIL",`No email templates directory found. Tried paths: ${e.join(", ")}`);return e[0]}function loadEmailTemplate(e){const t=getEmailTemplatesPath(),a=path_1.default.join(t,`${e}.html`);try{return fs_1.default.readFileSync(a,"utf-8")}catch(t){throw(0,error_1.createError)({statusCode:500,message:`Email template '${e}' not found at ${a}`})}}function replaceTemplateVariables(e,t){if("string"!=typeof e){console_1.logger.error("EMAIL","Template is not a string");return""}return Object.entries(t).reduce((e,[t,a])=>{if(void 0===a){console_1.logger.warn("EMAIL",`Variable ${t} is undefined`);return e}return e.replace(new RegExp(`%${t}%`,"g"),String(a))},e)}function processStandaloneTemplate(e,t){return replaceTemplateVariables(loadEmailTemplate(e),t)}function getAvailableTemplates(){const e=getEmailTemplatesPath();try{return fs_1.default.readdirSync(e).filter(e=>e.endsWith(".html")).map(e=>e.replace(".html",""))}catch(e){console_1.logger.error("EMAIL","Error reading templates directory",e);return[]}}function validateTemplateVariables(e,t){const a=/%([A-Z_]+)%/g,r=new Set;let l;for(;null!==(l=a.exec(e));)r.add(l[1]);const o=Array.from(r).filter(e=>!(e in t)||void 0===t[e]);return{isValid:0===o.length,missingVariables:o}}var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});exports.EMAIL_TEMPLATES=void 0;exports.loadEmailTemplate=loadEmailTemplate;exports.replaceTemplateVariables=replaceTemplateVariables;exports.processStandaloneTemplate=processStandaloneTemplate;exports.getAvailableTemplates=getAvailableTemplates;exports.validateTemplateVariables=validateTemplateVariables;const fs_1=__importDefault(require("fs")),path_1=__importDefault(require("path")),error_1=require("../utils/error"),console_1=require("./console");exports.EMAIL_TEMPLATES={GENERAL:"generalTemplate",WELCOME:"welcome",NOTIFICATION:"notification"};