import { redirect } from 'next/navigation'
import { getSession } from '@/lib/auth'
import { fetchJobsPageData } from '@/actions/jobs-page'
import JobsBoard from '@/components/jobs/jobs-board'
import JobsTimeFilter from '@/components/jobs/jobs-time-filter'

export const metadata = { title: 'Jobs — Scrum4Me' }

export default async function JobsPage() {
  const session = await getSession()
  if (!session.userId) redirect('/login')

  const data = await fetchJobsPageData()
  if (!data) redirect('/login')

  return (
    <main className="flex-1 flex flex-col overflow-hidden">
      <div className="px-6 py-4 border-b shrink-0 flex items-center justify-between gap-3">
        <h1 className="text-lg font-semibold">Jobs</h1>
        <JobsTimeFilter />
      </div>
      <div className="flex-1 overflow-hidden">
        <JobsBoard initialActiveJobs={data.activeJobs} initialDoneJobs={data.doneJobs} isDemo={session.isDemo ?? false} />
      </div>
    </main>
  )
}
