package logic

import (
	"fonchain-fiee/pkg/e"
	"github.com/gin-gonic/gin"
	"strings"
)

func GetLanguage(c *gin.Context) string {
	lang := c.Request.Header.Get("Accept-Language")
	lang = strings.Split(lang, ",")[0]
	if lang == "zh-CN" || lang == "zh" || lang == "ZhCN" {
		lang = "ZhCN"
	} else if lang == "zh-TW" || lang == "ZhTW" {
		lang = "ZhTW"
	} else if lang == "en" || lang == "EN" {
		lang = "EN"
	}
	return lang
}

func ConvertOfflineMsg(c *gin.Context, key string) string {
	language := GetLanguage(c)
	switch language {
	case "EN":
		return e.OfflineMap[strings.Join([]string{key, "EN"}, "")]
	case "ZhCN":
		return e.OfflineMap[strings.Join([]string{key, "ZhCN"}, "")]
	case "ZhTW":
		return e.OfflineMap[strings.Join([]string{key, "ZhTW"}, "")]
	default:
		return key
	}
}

func ConvertLoginMsg(c *gin.Context, key string) string {
	language := GetLanguage(c)
	switch language {
	case "EN":
		return e.LoginMap[strings.Join([]string{key, "EN"}, "")]
	case "ZhCN":
		return e.LoginMap[strings.Join([]string{key, "ZhCN"}, "")]
	case "ZhTW":
		return e.LoginMap[strings.Join([]string{key, "ZhTW"}, "")]
	default:
		return key
	}
}

func ConvertWeek(language string, week int32) string {
	switch language {
	case "EN":
		switch week {
		case 1:
			return "Monday"
		case 2:
			return "Tuesday"
		case 3:
			return "Wednesday"
		case 4:
			return "Thursday"
		case 5:
			return "Friday"
		case 6:
			return "Saturday"
		case 7:
			return "Sunday"
		}
	case "ZhCN":
		switch week {
		case 1:
			return "星期一"
		case 2:
			return "星期二"
		case 3:
			return "星期三"
		case 4:
			return "星期四"
		case 5:
			return "星期五"
		case 6:
			return "星期六"
		case 7:
			return "星期日"
		}
	case "ZhTW":
		switch week {
		case 1:
			return "星期一"
		case 2:
			return "星期二"
		case 3:
			return "星期三"
		case 4:
			return "星期四"
		case 5:
			return "星期五"
		case 6:
			return "星期六"
		case 7:
			return "星期日"
		}
	}
	return ""
}

func ConvertAmPm(language string, amPm string) string {
	switch language {
	case "EN":
		switch amPm {
		case "上午":
			return "AM"
		case "下午":
			return "PM"
		}
	}
	return amPm
}

func ConvertOaMsg(c *gin.Context, key string) string {
	language := GetLanguage(c)
	switch language {
	case "EN":
		return e.GetMsgEN(strings.Join([]string{key, "EN"}, ""))
	case "ZhCN":
		return e.GetMsgZhCN(strings.Join([]string{key, "ZhCN"}, ""))
	case "ZhTW":
		return e.GetMsgZhTW(strings.Join([]string{key, "ZhTW"}, ""))
	default:
		return key
	}
}
