{% import (
  "golang.org/x/text/language"
  "golang.org/x/text/message"

  "source.toby3d.me/toby3d/home/internal/domain"
) %}

{% interface Pager {
  Body()
  T(format message.Reference, v ...any)
  Title()
  Lang()
  Dir()
} %}

{% code
type BaseOf struct {
  printer *message.Printer
  site *domain.Site
}

func NewBaseOf(site *domain.Site) BaseOf {
  return BaseOf{
    site: site,
    printer: message.NewPrinter(language.Make(site.Language.Code())),
  }
}
%}

{% stripspace %}
{% func (b BaseOf) Title() %}
  {%s b.site.Title %}
{% endfunc %}

{% func (b BaseOf) T(key message.Reference, a ...any) %}
  {%s b.printer.Sprintf(key, a...) %}
{% endfunc %}

{% func (b BaseOf) Body() %}{% endfunc %}

{% func (b BaseOf) Lang() %}
  {%s b.site.Language.Lang() %}
{% endfunc %}

{% func (b BaseOf) Dir() %}
  {%s b.site.Language.Dir().String() %}
{% endfunc %}

{% func Template(p Pager) %}
  <!DOCTYPE html>
  <html lang="{%= p.Lang() %}" dir="{%= p.Dir() %}">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">

      <title>{%= p.Title() %}</title>
    </head>

    <body>
      {%= p.Body() %}
    </body>
  </html>
{% endfunc %}
{% endstripspace %}
