<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="ui" uri="http://egovframework.gov/ctl/ui" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<script type="text/javascript">
    $(document).on('click', '#checkId', function (){
        checkId();
    })

    function checkId(){
        if(inputCheck()){
            $.ajax({
                url: "/searchUserInfo",
                type: "GET",
                data: {
                    name: $("#username").val(),
                    company: $("#company").val(),
                    email: $("#email").val()
                },
                success: function (result) {
                    checkIdAfter(result)
                },
                error: function (request, status, error) {
                    alert("가입정보가 일치 하지 않습니다.\n 관리자에게 문의해주세요.");
                }
            });
        }
    }

    function inputCheck(){
        if(!$("#username").val()){
            alert("이름을 입력해주세요.")
            return false;
        }
        if(!$("#company").val()){
            alert("회사명을 입력해주세요.")
            return false;
        }
        if(!$("#email").val()){
            alert("이메일을 입력해주세요.")
            return false;
        }
        return true;
    }

    function checkIdAfter(result) {
        if(result==="userNull"){
            alert("입력된 가입 정보가 없습니다.")
        }else{
            alert("해당 정보로 가입된 ID는 "+result+" 입니다.")
        }
    }
</script>

<div class="row justify-content-end">
    <div class="col-12 row m-1">
        <label for="username" class="col-4 text-end">이름</label>
        <div class="col-8">
            <input type="text" class="form-control" id="username">
        </div>
    </div>

    <div class="col-12 row m-1">
        <label for="username" class="col-4 text-end">회사명</label>
        <div class="col-8">
            <input type="text" class="form-control" id="company">
        </div>
    </div>

    <div class="col-12 row m-1">
        <label for="username" class="col-4 text-end">email</label>
        <div class="col-8">
            <input type="email" class="form-control" id="email">
        </div>
    </div>

    <div class="col-8">
        <button type="button" id="checkId" class="btn btn-primary m-3">가입정보 확인</button>
    </div>

</div>