#!/bin/sh
set -eu

CONTAINER="${1:-reactive-resume-reactive-resume-1}"

docker exec -u root -i "$CONTAINER" sh <<'SH'
set -eu

PUBLIC_FILE="/app/apps/web/.output/public/assets/file-D5WsIgJH.js"
SSR_FILE="/app/apps/web/.output/server/_ssr/pdf-document-COfeOLVC.mjs"

cp "$PUBLIC_FILE" "$PUBLIC_FILE.bak-filename" 2>/dev/null || true
cp "$SSR_FILE" "$SSR_FILE.bak-filename" 2>/dev/null || true

node - <<'NODE'
const fs = require('fs');

const publicFile = '/app/apps/web/.output/public/assets/file-D5WsIgJH.js';
let publicJs = fs.readFileSync(publicFile, 'utf8');
publicJs = publicJs.replace(
  /function t\(t,n\)\{return`\$\{e\(t\)\}\$\{n\?`\.\$\{n\}`:""\}`\}/,
  'function t(e,t){let n=(e||"resume").toString().trim()||"resume";return`${n}${t?`.${t}`:""}`}'
);
fs.writeFileSync(publicFile, publicJs);

const ssrFile = '/app/apps/web/.output/server/_ssr/pdf-document-COfeOLVC.mjs';
let ssr = fs.readFileSync(ssrFile, 'utf8');
ssr = ssr.replace(
  /function generateFilename\(prefix, extension\) \{\n\s*return `\$\{slugify\(prefix\)\}\$\{extension \? `\.\$\{extension\}` : ""\}`;\n\}/,
  'function generateFilename(prefix, extension) {\n\tconst filename = (prefix || "resume").toString().trim() || "resume";\n\treturn `${filename}${extension ? `.${extension}` : ""}`;\n}'
);
fs.writeFileSync(ssrFile, ssr);
NODE
SH
