/**
 * Background: void — Apple-keynote-style near-black with vignette.
 *
 * Pure #000 reads too aggressively on screen; #0A0A0A gives the deck
 * enough warmth to feel "considered". A single very soft centred
 * vignette (slightly lifted) adds dimensional depth without bringing
 * colour into the slide.
 */
import { SLIDE_DIMENSIONS } from '../grid.js';
import { shade } from '../palettes.js';

export default function applyVoid(slide, resolved) {
  const palette = resolved.palette;
  const voidColor = isDarkHex(palette.bg) ? palette.bg : '0A0A0A';
  slide.background = { color: voidColor };

  const W = SLIDE_DIMENSIONS.width;
  const H = SLIDE_DIMENSIONS.height;
  const lift = shade(voidColor, 8);
  slide.addShape('ellipse', {
    x: -W * 0.2, y: -H * 0.2, w: W * 1.4, h: H * 1.4,
    fill: { color: lift, transparency: 70 },
    line: { type: 'none' },
  });
}

function isDarkHex(hex) {
  const s = String(hex).replace(/^#/, '');
  if (!/^[0-9A-Fa-f]{6}$/.test(s)) return false;
  const r = parseInt(s.slice(0, 2), 16);
  const g = parseInt(s.slice(2, 4), 16);
  const b = parseInt(s.slice(4, 6), 16);
  return (0.299 * r + 0.587 * g + 0.114 * b) < 110;
}
