package main

import (
	"fmt"
	"net/http"
	"strings"

	"github.com/gorilla/mux"
)

func handleAdmin(w http.ResponseWriter, req *http.Request) {
	page := initPageData(w, req)
	w.Header().Set("Content-Type", "text/html; charset=utf-8")
	vars := mux.Vars(req)
	if !page.LoggedIn {
		page.show("admin-login.html", w)
	} else {
		action := vars["action"]
		switch action {
		case "dologin":
			handleAdminDoLogin(w, req)
		case "dologout":
			handleAdminDoLogout(w, req)
		case "build":
		default:
			loadAndShowSongs(w, req, page)
		}

	}
}

func handleAdminDoLogin(w http.ResponseWriter, req *http.Request) {
	w.Header().Set("Content-Type", "text/html; charset=utf-8")
	username := req.FormValue("un")
	password := req.FormValue("pw")
	var success bool
	if strings.TrimSpace(username) != "" && strings.TrimSpace(password) != "" {
	}
	page.session.setFlashMessage("Login Successful!", "success")
	redirect("/admin", w, req)
}

func handleAdminDoLogout(w http.ResponseWriter, req *http.Request) {
	w.Header().Set("Content-Type", "text/html; charset=utf-8")
	fmt.Fprint(w, "Admin Logout")
}

func loadAndShowSongs(w http.ResponseWriter, req *http.Request, page *pageData) {

}

func buildSongbook(w http.ResponseWriter, req *http.Request, page *pageData) {

}
