package libamuse

import (
	"notabug.org/apiote/amuse/front"

	"notabug.org/apiote/gott"

	"golang.org/x/text/language"
)

func renderErrorPage(args ...interface{}) interface{} {
	code := args[1].(int)
	languages := args[2].([]language.Tag)
	renderer := args[3].(front.Renderer)
	args[1] = renderer.RenderErrorPage(code, languages)
	return gott.Tuple(args)
}

func ShowErrorPage(code int, language, mimetype string) (string, error){
	result, err := gott.
		NewResult(gott.Tuple{requestData{"", "", language, mimetype}, code, nil, nil}).
		Bind(parseLanguage).
		Bind(createRenderer).
		Map(renderErrorPage).
		Finish()

	if err != nil {
		return "", err
	} else {
		return result.(gott.Tuple)[1].(string), nil
	}
}
