"use client"
import React from 'react'
import { craeteBoard } from '@/app/actions/boardActions';
import { redirect } from 'next/navigation';

const NewBoardPage = () => {
    async function handleNewBoardSubmit(formData: FormData){
        const boardName = formData.get('name')?.toString() || '';
        const {id} = await craeteBoard(boardName);
        redirect(`/boards/${id}`)
    }


  return (
    <div>
        <form action={handleNewBoardSubmit} className='max-w-xs block'>
            <h1 className='text-2xl mb-4'>Create new board</h1>
            <input type="text" name='name' placeholder='board name' className='w-full outline-none p-2 border border-[#164863] rounded-md'/>
            <button type="submit" className='w-full mt-2'>Create board</button>
        </form>
    </div>
  )
}

export default NewBoardPage