package main

import (
	"github.com/go-chi/chi"
	"github.com/go-chi/chi/middleware"
	_ "github.com/mattn/go-sqlite3"
	"log"
	"net/http"
	"os"
	"path/filepath"
)


func main() {
	log.Println("Launching TODO App")
	log.Println("Generating the routes...")

	workDir, _ := os.Getwd()
	filesDir := filepath.Join(workDir, "static")

	router := chi.NewRouter()
	router.Use(middleware.Logger)

	router.Get("/", indexHandler)
	router.Get("/edit/{id:[0-9]+}", editHandler)

	router.Post("/create", createHandler)
	router.Post("/toggle/{id:[0-9]+}", toggleHandler)
	router.Post("/update/{id:[0-9]+}", updateHandler)
	router.Post("/delete/{id:[0-9]+}", deleteHandler)

	fileServer(router, "/static", http.Dir(filesDir))

	log.Println("Serving the page on port 1337")
	http.ListenAndServe(":1337", router)
}
