const fs = require('fs');
const path = require('path');

const root = path.resolve(__dirname, '../..');
const tenantLogo = path.join(root, 'public-tis', 'branding', 'logo.png/');
const defaultLogo = path.join(root, 'src', 'assets', 'images', 'logo.png');
const targetLogo = path.join(root, 'src', 'tenants', 'tis', 'assets', 'images', 'logo.png');

const source = fs.existsSync(tenantLogo) ? tenantLogo : defaultLogo;

if (!fs.existsSync(source)) {
  console.warn(
    `[prepare-tis-logo] No logo source found. Checked: ${tenantLogo} and ${defaultLogo}`,
  );
  process.exit(0);
}

fs.mkdirSync(path.dirname(targetLogo), { recursive: true });
fs.copyFileSync(source, targetLogo);
console.log(
  `[prepare-tis-logo] Using logo: ${path.relative(root, source)} -> ${path.relative(root, targetLogo)}`,
);
