import React, { useState } from 'react'
import { Redirect } from 'react-router-dom';
import './Home.css'

function Home() {
    const [name, setName] = useState('')
    const [done, setDone] = useState(false)

    const handleChange = (event) => {
        setName(event.target.value)
    }

    function checking(event) {
        if (!name) {
            alert('이름을 입력하세요')
        }
        else {
            alert('입력하신 이름은' + name + '입니다.')
            localStorage.setItem('name', name)
            setDone(true)
        }
    }

    return (
        <>
            {done ? <Redirect to='/quiz' /> : ''}
           <div className="d-flex justify-content-center ">
            <table className="table table-borderless" style={{width : "500px"}}>
                <thead className="text-center">
                    <tr  style={{height:"180px"}}></tr>
                </thead>
                <tbody className="text-center">
                    <tr>
                        <td>이름 입력<input className="ml-2 inputBox" onChange={handleChange} /></td>
                    </tr>
                    <tr>
                        <td>비밀번호<input className="ml-2 inputBox" onChange={handleChange} /></td>
                    </tr>
                    <tr>
                        <td><button className="mt-4 btn btn-dark" onClick={checking}>Quiz Start !</button></td>
                    </tr>
                </tbody>
            </table>
            </div>
            {/* 
                    <div className="container-fluid">
                        <div className="text-center">
                            <div>
                                이름을 입력하세요
                    </div>
                            <input className="inputBox" onChange={handleChange} />
                            <div className='Box2'>
                                <button className="btn btn-dark" onClick={checking}>Quiz Start !</button>
                            </div>
                        </div>
                    </div> */}

            <div>계산수학</div>
        </>
    )
}
export default Home;
