package brass

import (
	"html/template"
	"net/http"
	"strings"
)

func loginPage(w http.ResponseWriter, r *http.Request, phone string, phoneErr, codeErr error) {
	if strings.HasPrefix(r.Header.Get("Accept"), "text/html") {
		err := template.Must(template.New("login.html").Parse(loginHTML)).Execute(w, struct {
			Phone      string
			PhoneError error
			CodeError  error
		}{
			Phone:      phone,
			PhoneError: phoneErr,
			CodeError:  codeErr,
		})
		if err != nil {
			panic(err)
		}
		return
	}
	if phoneErr != nil {
		http.Error(w, phoneErr.Error(), http.StatusBadRequest)
	} else if codeErr != nil {
		http.Error(w, codeErr.Error(), http.StatusBadRequest)
	}
}
