// Sample data for the /admin/email-templates preview pane. Each preview
// request renders the proposed subject + body against this fixed payload
// so the admin sees the layout exactly as it will look in production for a
// representative case. Sample data is server-authoritative; the editor
// can't override it (out of scope for v1 — see design doc §9).
package services

// EmailTemplateSampleData returns a fresh sample payload for (key, lang).
// `slot` is honoured for deadline_digest only ("morning" / "evening"); other
// keys ignore it.
func EmailTemplateSampleData(key, lang, slot string) map[string]any {
	switch key {
	case EmailTemplateKeyInvitation:
		return invitationSample(lang)
	case EmailTemplateKeyAddUserWelcome:
		return addUserWelcomeSample(lang)
	case EmailTemplateKeyDeadlineDigest:
		return deadlineDigestSample(lang, slot)
	case EmailTemplateKeyBase:
		return baseSample(lang)
	default:
		return map[string]any{}
	}
}

func invitationSample(lang string) map[string]any {
	if lang == "en" {
		return map[string]any{
			"InviterName":  "Maria Schmidt",
			"InviterEmail": "maria.schmidt@hlc.com",
			"ToEmail":      "new.colleague@hlc.com",
			"Message":      "Hi — I think you'd find Paliad useful. Have a look.",
			"RegisterURL":  "https://paliad.de/login",
		}
	}
	return map[string]any{
		"InviterName":  "Maria Schmidt",
		"InviterEmail": "maria.schmidt@hlc.com",
		"ToEmail":      "neu.kollege@hlc.de",
		"Message":      "Hallo Kolleg:in — ich glaube Paliad wäre nützlich für dich. Schau es dir an.",
		"RegisterURL":  "https://paliad.de/login",
	}
}

func deadlineDigestSample(lang, slot string) map[string]any {
	isEvening := slot == "evening"
	overdue := []map[string]any{
		{
			"DueDate":          "2026-04-27",
			"Title":            ifLang(lang, "Beschwerde gegen EP-Anmeldung einreichen", "File appeal against EP application"),
			"ProjectReference": "HL-2024-0083",
			"ProjectTitle":     "Acme vs Beta GmbH",
			"OwnerName":        "Maria Schmidt",
			"IsOtherOwner":     true,
			"URL":              "https://paliad.de/deadlines/sample-overdue-1",
		},
	}
	dueToday := []map[string]any{
		{
			"DueDate":          "2026-04-29",
			"Title":            ifLang(lang, "Klageerwiderung einreichen", "File reply to complaint"),
			"ProjectReference": "HL-2025-0011",
			"ProjectTitle":     "Gamma AG vs Delta Inc",
			"OwnerName":        "Self",
			"IsOtherOwner":     false,
			"URL":              "https://paliad.de/deadlines/sample-due-today-1",
		},
		{
			"DueDate":          "2026-04-29",
			"Title":            ifLang(lang, "Vollmacht prüfen und gegenzeichnen", "Review and counter-sign power of attorney"),
			"ProjectReference": "HL-2025-0014",
			"ProjectTitle":     "",
			"OwnerName":        "Self",
			"IsOtherOwner":     false,
			"URL":              "https://paliad.de/deadlines/sample-due-today-2",
		},
	}
	dueWarning := []map[string]any{
		{
			"DueDate":          "2026-05-06",
			"Title":            ifLang(lang, "Stellungnahme zur Erteilung vorbereiten", "Prepare response to grant"),
			"ProjectReference": "HL-2025-0007",
			"ProjectTitle":     "Epsilon Ltd",
			"OwnerName":        "Self",
			"IsOtherOwner":     false,
			"URL":              "https://paliad.de/deadlines/sample-warning-1",
		},
	}
	return map[string]any{
		"Slot":            slot,
		"IsEvening":       isEvening,
		"Overdue":         overdue,
		"OverdueCount":    len(overdue),
		"DueToday":        dueToday,
		"DueTodayCount":   len(dueToday),
		"DueWarning":      dueWarning,
		"DueWarningCount": len(dueWarning),
		"OpenTotal":       len(dueToday) + len(dueWarning),
		"DeadlinesURL":    "https://paliad.de/deadlines",
	}
}

// t-paliad-223 Slice B (#49) — sample data for the Add-User welcome mail.
// The variable contract mirrors what UserService.AdminCreateUserFull
// passes to MailService.SendTemplate at runtime.
func addUserWelcomeSample(lang string) map[string]any {
	if lang == "en" {
		return map[string]any{
			"InviterName":  "Maria Schmidt",
			"InviterEmail": "maria.schmidt@hlc.com",
			"ToEmail":      "new.colleague@hlc.com",
			"MagicLink":    "https://supabase.paliad.de/auth/v1/verify?token=…",
			"BaseURL":      "https://paliad.de",
			"Firm":         "HLC",
		}
	}
	return map[string]any{
		"InviterName":  "Maria Schmidt",
		"InviterEmail": "maria.schmidt@hlc.com",
		"ToEmail":      "neu.kollege@hlc.de",
		"MagicLink":    "https://supabase.paliad.de/auth/v1/verify?token=…",
		"BaseURL":      "https://paliad.de",
		"Firm":         "HLC",
	}
}

func baseSample(lang string) map[string]any {
	subj := "Beispielbetreff"
	if lang == "en" {
		subj = "Example subject"
	}
	return map[string]any{
		"Subject": subj,
	}
}

func ifLang(lang, de, en string) string {
	if lang == "en" {
		return en
	}
	return de
}
