import { Handlers, PageProps } from '$fresh/server.ts'
import { Task } from '@homeman/models.ts'
import { Routine } from '@homeman/islands/Routine.tsx'
import { kv } from '@homeman/db.ts'
// import { db, kv, Todo, UserWithTodos } from '@homeman/models.ts'

interface Data {
	tasks: Task[]
}

export const handler: Handlers = {
	async GET(_req, ctx) {
		const tasks = (await Array.fromAsync(kv.list({ prefix: ['task'] }))).map(
			(r) => r.value
		)
		console.log({ tasks })
		return ctx.render({ tasks })
	},
}

export default function Page(props: PageProps<Data>) {
	return <Routine tasks={props.data.tasks} />
}
