
import * as EgovNet from "../../api/egovFetch";

import Row from "react-bootstrap/Row";
import Col from "react-bootstrap/Col";
import Form from "react-bootstrap/Form";
import Button from "react-bootstrap/Button";


function IdFindForm(){

    const findId = (e) => {
        e.preventDefault();
        e.stopPropagation();
        const form = e.currentTarget;
        if(!form.email.value){
            alert("이메일을 입력해주세요.")
        }else{
            EgovNet.requestFetch(
                "/auth/findId",
                {
                    method: "POST",
                    headers: {
                        'Content-type': 'application/json'
                    },
                    body: JSON.stringify({email: form.email.value})
                },
                (resp) => {
                    document.querySelector("#findResultLabel").innerText = resp.resultMessage;
                })
        }
    }

    return (
        <Form onSubmit={findId} noValidate>
            <Form.Group as={Row} className="mb-3" controlId="formHorizontalEmail">
                <Form.Label column sm={2}>
                    이메일
                </Form.Label>
                <Col sm={10}>
                    <Form.Control type="email" placeholder="Email" name="email" required />
                    <Form.Control.Feedback type={"invalid"} >메일을 입력해주세요.</Form.Control.Feedback>
                </Col>
            </Form.Group>
            <Row className="mb-3">
                <Form.Label column xs={{span:8, offset:2}} id="findResultLabel"></Form.Label>
                <Col xs={2}>
                    <Button type="submit">찾기</Button>
                </Col>
            </Row>
        </Form>
    );
}

export default IdFindForm;