/**
 * Background: geometric.
 *
 * Decorative shapes in corners + along edges. Style depends on the
 * theme's decoration config:
 *   - editorial: small hairline rules, a single accent square
 *   - tech:      diagonal slashes, soft blobs in corners
 *   - data:      a single thin underline + a tiny corner tick
 *
 * Always backgrounded — sits behind content but in front of `bg`.
 */
import { SLIDE_DIMENSIONS } from '../grid.js';
import { shade } from '../palettes.js';

export default function applyGeometric(slide, resolved) {
  slide.background = { color: resolved.palette.bg };
  const style = resolved.decoration?.geometric?.style || resolved.theme.family;
  const density = resolved.decoration?.geometric?.density || 'medium';

  if (style === 'editorial') {
    // A small accent square in the bottom-right + a hairline rule at top.
    slide.addShape('rect', {
      x: SLIDE_DIMENSIONS.width - 0.7,
      y: SLIDE_DIMENSIONS.height - 0.7,
      w: 0.35, h: 0.35,
      fill: { color: resolved.palette.accent, transparency: 30 },
      line: { type: 'none' },
    });
    if (density !== 'minimal') {
      slide.addShape('line', {
        x: 0.4, y: 0.32, w: 1.8, h: 0,
        line: { color: resolved.palette.primary, width: 1 },
      });
    }
  } else if (style === 'tech') {
    // A large soft blob in the top-right + a diagonal accent line in
    // the bottom-left. Reads as "modern keynote".
    slide.addShape('ellipse', {
      x: SLIDE_DIMENSIONS.width - 3.5,
      y: -1.5,
      w: 5, h: 4,
      fill: { color: resolved.palette.primary, transparency: 70 },
      line: { type: 'none' },
    });
    slide.addShape('ellipse', {
      x: -1.5,
      y: SLIDE_DIMENSIONS.height - 1.5,
      w: 3.5, h: 3.5,
      fill: { color: resolved.palette.accent, transparency: 75 },
      line: { type: 'none' },
    });
    if (density !== 'minimal') {
      slide.addShape('line', {
        x: 0.6, y: SLIDE_DIMENSIONS.height - 0.4, w: 1.6, h: 0,
        line: { color: resolved.palette.accent, width: 1.5 },
      });
    }
  } else if (style === 'data') {
    // A single thin "rule" under the header + a tiny corner tick.
    slide.addShape('rect', {
      x: 0, y: SLIDE_DIMENSIONS.height - 0.06,
      w: SLIDE_DIMENSIONS.width, h: 0.06,
      fill: { color: shade(resolved.palette.subtle, 60), transparency: 50 },
      line: { type: 'none' },
    });
    slide.addShape('rect', {
      x: SLIDE_DIMENSIONS.width - 0.5,
      y: 0,
      w: 0.5, h: 0.06,
      fill: { color: resolved.palette.primary },
      line: { type: 'none' },
    });
  }
}
