// Lights. Currently a directional sun (the engine's primary light). Add it to a scene like any node.

import { Color, type ColorInput } from "../core/color"
import type { Vec3Like } from "../math/vec"
import { Node } from "./Node"

export type SunOptions = {
  /** Light direction (points where the light travels). Defaults to a typical key-light angle. */
  direction?: Vec3Like
  /** Luminous intensity. */
  intensity?: number
  color?: ColorInput
  /**
   * Shadow quality (default 1):
   *   0 - no shadows
   *   1 - standard (1024 shadow map, hard PCF edges)
   *   2 - high (2048 + stable, soft contact-hardening edges)
   *   3 - best (4096 + stable, PCSS soft shadows)
   * Higher values cost more GPU/memory.
   */
  shadowsQuality?: 0 | 1 | 2 | 3
}

export class Light extends Node {
  /** A directional sun light. */
  static sun(options: SunOptions = {}): Light {
    const light = new Light()
    const [ dx, dy, dz ] = options.direction ?? [ 0.548267, -0.473983, -0.689016 ]
    _creator.createSunLight(
      light.id, dx, dy, dz,
      options.intensity ?? 100000,
      Color.toPackedRgb(options.color ?? 0xffffff),
      options.shadowsQuality ?? 1,
    )
    return light
  }
}
