import { route } from 'preact-router'
import { useEffect, useState } from 'preact/hooks'
import { Problem as ProblemModel } from '../../shared/model'
import { Header } from '../components/Header'

import { Problem } from '../components/Problem'
import { Select } from '../components/Select'
import { useResource, useCurrentUser } from '../hooks'

export const HomePage = () => {
    const [user] = useCurrentUser()
    const [problems] = useResource<ProblemModel[]>('/api/problems', [])

    console.log(problems)

    return (
        <main class="page-home">
            <Header {...{ user }} />
            <div class="board">
                <div class="fill-row board-controls">
                    <div class="sort-order">
                        <Select
                            value="oldest"
                            options={{
                                'latest': 'Prima più recenti',
                                'oldest': 'Prima più antichi',
                                'top-solved': 'Prima più risolti',
                                'least-solved': 'Prima meno risolti',
                            }}
                        />
                    </div>
                </div>

                {problems.map(p => (
                    <Problem {...p} />
                ))}
            </div>
        </main>
    )
}
