import Form from "react-bootstrap/Form";
import Row from "react-bootstrap/Row";
import Col from "react-bootstrap/Col";
import Button from "react-bootstrap/Button";
import * as EgovNet from "../../api/egovFetch";

function PwFindForm(){

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

    return (
        <Form onSubmit={findPw} noValidate>
            <Form.Group as={Row} className="mb-3" controlId="formHorizontalEmail">
                <Form.Label column sm={12} className="text-center">
                    비밀번호를 찾고자하는 아이디와 이메일을 입력해 주세요.
                </Form.Label>
                <Col sm={12} className="input-group h_50">
                    <span className="input-group-text">
                        <img src="/assets/images/icon_id.png" alt="email icon" />
                    </span>
                    <Form.Control type="text" name="id" placeholder="아이디" required className={"radius_r shadow-none"} />
                </Col>
            </Form.Group>
            <Form.Group as={Row} controlId="formHorizontalEmail">
                <Col sm={12} className="input-group h_50">
                    <span className="input-group-text">
                        <img src="/assets/images/mail.png" alt="email icon" />
                    </span>
                    <Form.Control type="email" name="email" placeholder="이메일" required className={"radius_r shadow-none"} />
                </Col>
            </Form.Group>
            <Row className="mb-3">
                <Form.Label column xs={{span:8, offset:2}} id="findResultLabel" className={"text-center f_17"}></Form.Label>
                <Col xs={12}>
                    <Button type="submit" className={"btn btn-22498E btn-lg w-100 f_15"}>비밀번호 찾기</Button>
                </Col>
            </Row>
        </Form>
    );
}

export default PwFindForm;