// import bg from './img_study.jpg'
// import korea from './img_korea.jpg'
import React, { useState} from 'react'
import { Redirect } from 'react-router-dom';

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

    const [admin, setAdmin] = useState(false);

    const handleChangename = (event) => {
        setName(event.target.value)
    }
    const handleChangepassword = (event) => {
        SetPassword(event.target.value)
    }

    function handleClick() {
        if (!name) {
            alert('이름을 입력하세요')
        }
        else if (!password) {
            alert('비밀번호를 입력하세요')
        }
        else if (name === 'admin' && password === '0001') {
            console.log('done')

            return (setAdmin(true)

            )
        }
        else if (password !== '0319') {
            alert('유효한 비밀번호를 입력하세요')
        }
        else {
            alert('입력하신 이름은 ' + name + '입니다.')
            localStorage.setItem('name', name)
            localStorage.setItem('password', password)
            setDone(true)
        }

    }




    return (
        <>
            {admin ? <Redirect to='/admin' /> : ''}

            {done ? <Redirect to='/quiz' /> : ''}
            <h1 className="h-3 mb-5 mx-3 text-center bg-danger py-2">
                KOREA UNIVERSITY
            </h1>
            
            <form className="d-flex justify-content-center">

                <div className="table table-bordered" style={{width: "400px" }}>

                    <label for="inputId" className="d-flex justify-content-center" >
                        정보 입력
                    </label>
                    <div className="form-group text-center">
                        <label for="inputName">
                            이름입력<input className="ml-3 inputBox" onChange={handleChangename} placeholder="Name"/>
                        </label>

                        <label for="inputPassword">
                            비밀번호<input type='password' className="ml-3 inputBox" onChange={handleChangepassword} placeholder="Password"/>
                        </label>
                        <div className="form-group for login">
                            <label for="inputLogin" className="d-flex justify-content-center">
                                <button className="mt-4 btn btn-dark" onClick={handleClick}>Login</button>
                            </label>
                        </div>
                    </div>
                </div>
            </form>
        </>

    )
}

export default Home;

