cd(@__DIR__)
using Pkg
Pkg.activate(@__DIR__)
CI = get(ENV, "CI", nothing) == "true" || get(ENV, "GITHUB_TOKEN", nothing) !== nothing
CI && Pkg.instantiate()

using InteractiveDynamics
using DynamicalSystems, DynamicalBilliards, Agents
using Documenter
using DocumenterTools: Themes

# %%
# download the themes
for file in ("juliadynamics-lightdefs.scss", "juliadynamics-darkdefs.scss", "juliadynamics-style.scss")
    download("https://raw.githubusercontent.com/JuliaDynamics/doctheme/master/$file", joinpath(@__DIR__, file))
end
# create the themes
for w in ("light", "dark")
    header = read(joinpath(@__DIR__, "juliadynamics-style.scss"), String)
    theme = read(joinpath(@__DIR__, "juliadynamics-$(w)defs.scss"), String)
    write(joinpath(@__DIR__, "juliadynamics-$(w).scss"), header*"\n"*theme)
end
# compile the themes
Themes.compile(joinpath(@__DIR__, "juliadynamics-light.scss"), joinpath(@__DIR__, "src/assets/themes/documenter-light.css"))
Themes.compile(joinpath(@__DIR__, "juliadynamics-dark.scss"), joinpath(@__DIR__, "src/assets/themes/documenter-dark.css"))

makedocs(
modules=[InteractiveDynamics, DynamicalSystems, DynamicalBilliards, Agents],
doctest=false,
sitename= "InteractiveDynamics",
root = @__DIR__,
format = Documenter.HTML(
    prettyurls = CI,
    assets = [
        asset("https://fonts.googleapis.com/css?family=Montserrat|Source+Code+Pro&display=swap", class=:css),
        ],
    ),
pages = [
    "Introduction" => "index.md",
    "Trajectory Evolution" => "trajectory.md",
    "Orbit Diagram" => "od.md",
    "Cobweb Diagram" => "cobweb.md",
    "Poincaré Surface of Section" => "psos.md",
    "Brainscanning PSOS" => "brainscan.md",
    "Billiards" => "billiards.md",
    "Agent Based Models" => "agents.md",
    # "Trajectory Highlighter" => "highlight.md",
],
)

if CI
    deploydocs(
        repo = "github.com/JuliaDynamics/InteractiveDynamics.jl.git",
        target = "build",
        push_preview = true
    )
end
