package components

import (
	"git.soup.land/soup/sxgo/ssr"
)

type Page struct {
	Title   string
	Content ssr.Renderable
	ShowNav bool
	HasAuth bool
}

func (p Page) Render(sw *ssr.Writer) error {
	sw.Tmpl(p, `
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta name="color-scheme" content="light dark">
	<meta name="darkreader-lock">
	<title>{{.Title}} - Lookbook</title>
	<link rel="stylesheet" href="{{staticURL "css/pico.min.css"}}">
	<link rel="stylesheet" href="{{staticURL "css/styles.css"}}">
</head>
<body>
	<header class="site-header">
		<div class="title">Lookbook</div>
		{{if .ShowNav}}
		<nav class="site-nav">
			<a href="/">All</a>
			<button type="button" class="ghost" onclick="auth()">Auth</button>
			<button type="button" class="ghost" onclick="logout()" {{if not .HasAuth}}hidden{{end}}>Logout</button>
		</nav>
		{{end}}
	</header>
	<main class="container">
`)

	p.Content.Render(sw)
	return sw.Tmpl(p, `
	</main>
	<script>
		window.LOOKBOOK_AUTH = {{if .HasAuth}}true{{else}}false{{end}};
	</script>
	<script src="{{staticURL "js/app.js"}}"></script>
</body>
</html>
`)
}
