/**
 * Kasy brand kit for the terminal.
 *
 * Centralizes logo, banner, headers, and boxed messages so every
 * command projects a consistent identity. Two header sizes:
 *  - printBanner(): full ASCII logo + gradient + tagline (kasy new, kasy add)
 *  - printCompactHeader(): one-line ✦ KASY + tagline (kasy doctor, upgrade, run)
 *
 * Box helpers wrap `boxen` so commands stop drawing ─── lines by hand.
 */

const kleur = require('kleur');
const gradient = require('gradient-string');
const boxenPackage = require('boxen');
const boxen = boxenPackage.default || boxenPackage;

// Kept around for accents and boxes; the wordmark itself is now plain white.
const BRAND_GRADIENT = ['#a78bfa', '#60a5fa'];
const brandGradient = gradient(BRAND_GRADIENT);

const DOMAIN_SUFFIX = kleur.gray('.dev');

function printBanner(_tr) {
  const bar = kleur.gray('─────────────────────────────────────────────────');
  const logo = [
    kleur.white('  ╦╔═ ╔═╗ ╔═╗ ╦ ╦'),
    kleur.white('  ╠╩╗ ╠═╣ ╚═╗ ╚╦╝'),
    `${kleur.white('  ╩ ╩ ╩ ╩ ╚═╝  ╩ ')} ${DOMAIN_SUFFIX}`,
  ].join('\n');

  console.log(`\n${bar}\n`);
  console.log(logo);
  console.log(`\n${bar}\n`);
}

function printCompactHeader(_tr) {
  console.log('');
  console.log(`  ${kleur.white('✦ KASY')}${DOMAIN_SUFFIX}`);
  console.log('');
}

function successBox(title, body, { padding = 1, marginTop = 1, marginBottom = 1 } = {}) {
  return boxen(
    `${brandGradient(`✦ ${title}`)}\n\n${body}`,
    {
      padding,
      margin: { top: marginTop, bottom: marginBottom, left: 1, right: 1 },
      borderStyle: 'round',
      borderColor: 'cyan',
    }
  );
}

function infoBox(title, body, { padding = 1, marginTop = 1, marginBottom = 1 } = {}) {
  return boxen(
    `${kleur.bold(title)}\n\n${body}`,
    {
      padding,
      margin: { top: marginTop, bottom: marginBottom, left: 1, right: 1 },
      borderStyle: 'round',
      borderColor: 'gray',
    }
  );
}

module.exports = {
  brandGradient,
  printBanner,
  printCompactHeader,
  successBox,
  infoBox,
};
