/**
 * Background: linear gradient (palette → shaded palette).
 *
 * pptxgenjs's slide.background has limited gradient support, so we
 * place a full-slide rect with a two-stop linear gradient fill BEHIND
 * everything else. This works identically in PowerPoint, Keynote, and
 * Google Slides.
 *
 * Direction: 45° from top-left to bottom-right. Two stops derived from
 * the palette: `bg` ↔ `bg shaded toward primary` for a subtle tint.
 */
import { SLIDE_DIMENSIONS } from '../grid.js';
import { mix } from '../palettes.js';

export default function applyGradient(slide, resolved) {
  // Solid fallback so the slide isn't transparent if the gradient shape
  // renders late.
  slide.background = { color: resolved.palette.bg };

  const stop0 = resolved.palette.bg;
  const stop1 = mix(resolved.palette.bg, resolved.palette.primary, 0.18);

  slide.addShape('rect', {
    x: 0, y: 0,
    w: SLIDE_DIMENSIONS.width,
    h: SLIDE_DIMENSIONS.height,
    fill: {
      type: 'gradient',
      gradientType: 'linear',
      angle: 135,
      stops: [
        { pos: 0,   color: stop0 },
        { pos: 100, color: stop1 },
      ],
    },
    line: { type: 'none' },
  });
}
