#lang racket/base

; Flag generator pages
(require
  xml
  "templates.rkt"
  "../webcontainer/weblets.rkt"
  "../generators/flag.rkt"
  "../graphics/vectorial.rkt")

(provide
  pages:flag
  pages:flag-raw
  pages:flag-about)

; Raw page
(define pages:flag-raw
  (raw-data-weblet
    #:content-type #"image/svg+xml;charset=utf-8"
    #:body
    (lambda (param)
      (string->bytes/utf-8
        (xexpr->string
          (vectorial->sxml-svg (flag-generate 600))))))) ; flag width: 600

; Flag page
(define pages:flag
  (pages:template
    #:title "Flag Generator"
    #:author "feuforeve.fr"
    #:stylesheets '("/css/flag.css")
    #:scripts '("/scripts/flag.js")
    #:on-load "getFlag();"
    #:content
    '(article
      (section
        (p
          (button ((onclick "getFlag();")) "New flag") " "
          (a ((id "download") (download "flag.svg")) "Save flag"))
        (p
          (section ((id "flag"))))
        (p "The generated flags are released under the "
           (a ((href "http://creativecommons.org/publicdomain/zero/1.0/"))
              "Creative Commons CC0 1.0 Universal (CC0 1.0) Public Domain Dedication") "."))
      )))

; About page
(define pages:flag-about
  (pages:template
    #:title "About the flag generator"
    #:author "Feufochmar"
    #:date "2020-05-01"
    #:content
    '(article
      (h3 "The generator")
      (p "The generator generates flags as svg images and display them on the generator page. "
          "The flags can be saved with the link provided. ")
      (h3 "Generation process")
      (p "The generator first chooses a set of color couples to use (a dark color and a light color). "
         "Then it chooses the main division of the flag (plain color, bicolor or tricolor, horizontal or vertical, ...). "
         "It terminates by choosing an overlay that adds elements like stars or crosses on the flag. "
         "The choice of overlay depends on the division. ")
      (p "The generator uses a rule when combining colors: light colors are placed above dark color (and vice-versa). "
         "This is inspired by a heraldic rule regarding how colors are combined: "
         "no metal (light color) on metal nor tincture (dark color) on tincture. "
         "The generator draws inspiration from heraldry and there are indeed many heraldic references "
         "inside the source code. ")
      (h3 "Why not providing a flag editor ?")
      (p "Maybe as a future feature. I need to design an intermediary format that describes a flag before being able to provide an editor. "
         "Currently, the generator directly outputs geometric shapes when generating the flag. ")
      (p "There exists websites allowing you to design flags. For instance "
         (a ((href "http://flag-designer.appspot.com/")) "Scrontch's Flag Designer") ". ")
      (h3 "Licence of the generated flags")
      (p "Since I don't care at all about what you do with the generated flags, "
         "the generated flags are released under the "
         (a ((href "http://creativecommons.org/publicdomain/zero/1.0/"))
         "Creative Commons CC0 1.0 Universal (CC0 1.0) Public Domain Dedication") ". "
         "You can still put a link to the generator or credit me if you want. ")
      )))
