'use strict';
import { readFile } from 'node:fs/promises';
import { getNow } from '../../../../fd-toolbox/time/date-time.js';
import { sendEmail } from '../../fd/fd-toolbox-web/mailing/fd-emails.js';
import { routes } from '../../../../fd-toolbox/routing/routes.js';
import { inviteCode } from '../../../../fd-toolbox/constants/internal-auth-constants.js';
import { getRequiredStringEnvSetting, getStringEnvSetting } from '../../../../fd-toolbox/infra/env-functions.js';
import { envSettingKeys } from '../../../common/infra/env-setting-keys.js';
import { workspaceInviteSubject } from './workspace-invite-constants.js';
import { getUserById } from '../../../fd-app-toolbox/server/users/user-db.js';
import { getHtmlTemplatesPath } from '../../html/email.js';
import { join } from 'node:path';
import { publicFolder } from '../../../../base-repo/app-constants/app-packages-names.js';
import { contentDisposition } from '../../../../fd-toolbox/constants/api-constants.js';
import { supportedImageTypes } from '../../../../fd-toolbox/constants/file-loader-data-types.js';
import { serverUrlPlaceholders } from '../../constants/url-placeholders.js';

var __defProp=Object['defineProperty'],__name=(_0x397f33,_0x5ac016)=>__defProp(_0x397f33,'name',{'value':_0x5ac016,'configurable':!![]});const logoFilename='logo.webp';async function afterCreate(_0x494159){const _0x3f49bc=_0x494159['createdResource']['email'],_0x4ab5d3=_0x494159['createdResource']['id'],_0x5121ea=getRequiredStringEnvSetting(envSettingKeys['baseUrl']),_0x5094ad=new URL(routes['register'],_0x5121ea);_0x5094ad['searchParams']['set'](inviteCode,_0x4ab5d3);const _0x3e0f4a=_0x5094ad['toString'](),_0xd2f4b7=getHtmlTemplatesPath('workspace-invite-template.html'),_0x329c07=await getUserById(_0x494159['createdResource']['createdByUserId']),_0x11295b=await readFile(_0xd2f4b7,{'encoding':'utf-8'}),_0x31e622=_0x11295b['replace'](serverUrlPlaceholders['callbackUrlPlaceholder'],_0x3e0f4a),_0x1b9e13=_0x31e622['replace']('{{inviterName}}',(_0x329c07['firstName']??'')+'\x20'+(_0x329c07['lastName']??''))['replaceAll']('{{projectName}}',getRequiredStringEnvSetting(envSettingKeys['projectName'])),_0x378450=getStringEnvSetting(envSettingKeys['supportLink']);let _0x1bec6d,_0x22e0f7='';if(_0x378450){const _0xf7217d=getHtmlTemplatesPath('workspace-invite-footer.html'),_0xc95f4=await readFile(_0xf7217d,{'encoding':'utf-8'});_0x22e0f7=_0xc95f4['replace']('{{supportLink}}',_0x378450);}_0x1bec6d=_0x1b9e13['replace']('{{contactSupport}}',_0x22e0f7);const _0x1cd77a={'to':[_0x3f49bc],'from':getRequiredStringEnvSetting(envSettingKeys['senderEmail']),'subject':workspaceInviteSubject,'body':_0x1bec6d,'attachments':[{'filename':logoFilename,'path':join(process['cwd'](),publicFolder['public'],publicFolder['images'],logoFilename),'cid':'unique@cid','contentDisposition':contentDisposition,'contentType':supportedImageTypes[-0x1*-0x1eb1+-0x5*-0x62b+-0x3d87]}]};await sendEmail(_0x1cd77a);}__name(afterCreate,'afterCreate');async function preCreate(_0x354ebd){if(!_0x354ebd['crudUpdateConfig']['isCreate'])return;const _0x570fad=getNow();_0x570fad['setMonth'](_0x570fad['getMonth']()+(0x144a+0x183*-0x17+0x9*0x19c)),_0x354ebd['createResource']['expirationDate']=_0x570fad;}__name(preCreate,'preCreate');

export { afterCreate, preCreate };
