#lang racket/base

; Functions to generate a palette of colors for use in flag generation
(require
  "../../base-generation/random.rkt")

(provide
  ; Palette structure accessors
  palette-main palette-secondary palette-main-dark?
  ; Palette generation
  palette-generate)

; Palette slot structure
; Contains 2 colors (a dark and a light) and a boolean indicating which one is the main color
(struct palette-slot
  (light
   dark
   main-dark?))

; A palette is a vector of palette slots - no need for new structure

; Get the main color
(define (palette-main palette index)
  (define slot (vector-ref palette index))
  (if (palette-slot-main-dark? slot)
      (palette-slot-dark slot)
      (palette-slot-light slot)))

; Get the secondary color
(define (palette-secondary palette index)
  (define slot (vector-ref palette index))
  (if (palette-slot-main-dark? slot)
      (palette-slot-light slot)
      (palette-slot-dark slot)))

; Get the information if the main is dark or light
(define (palette-main-dark? palette index)
  (palette-slot-main-dark?
    (vector-ref palette index)))

; Generate a palette from a list of dark colors and a list of light colors
(define (palette-generate nb-colors dark-colors light-colors)
  (define darks (random:sublist dark-colors nb-colors))
  (define lights (random:sublist light-colors nb-colors))
  (list->vector
    (map
      (lambda (d l)
        (palette-slot l d (random:boolean)))
      darks
      lights)))
