package fs

import (
	"context"
	"fmt"
	"html/template"
	"io/fs"

	"source.toby3d.me/toby3d/home/internal/theme"
)

type fileSystemThemeRepository struct {
	dir fs.FS
}

func NewFileSystemThemeRepository(dir fs.FS) theme.Repository {
	return &fileSystemThemeRepository{
		dir: dir,
	}
}

func (repo *fileSystemThemeRepository) Get(ctx context.Context, funcMap template.FuncMap) (*template.Template, error) {
	tpl, err := template.New("").Funcs(funcMap).ParseFS(repo.dir, "*.html")
	if err != nil {
		return nil, fmt.Errorf("cannot find baseof template: %w", err)
	}

	return tpl, nil
}
