<?php
include_once "{$_SERVER['DOCUMENT_ROOT']}/common.inc.php";
?>

<!DOCTYPE html>
<html lang="kr">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="description" content="Member Login">
  <title>(주)한양공업</title>

  <?php include _SVC_INC_PATH_ ."/header_common.php" ?>
  <!-- favicon 넣기 -->
</head>

<body>
  <div class="login-section">
    <div class="login-container">
      <div class="image-container">
        <div class="image-box"></div>
      </div>
      <div class="form-container">
        <div class="form-title">
          <p>LOGIN</p>
        </div>
        <form method="post" action="###" class="login-form" id="auth_login" name="auth_login">
          <div class="login-put-field">
            <label for="id_box">ID</label>
            <input type="text" id="member_id" name="member_id" data-defval="<?=$_COOKIE['kuls_save_session']?>">
          </div>
          <div class="login-put-field">
            <label for="pw_box">PASSWORD</label>
            <input type="password" id="member_auth" name="member_auth">
          </div>
          <div class="login-check-field">
            <input type="checkbox" name="save_id" id="save_id" data-defval="<?=$_COOKIE['kuls_save_session']?"Y":""?>">
            <label for="save_id">아이디 기억하기</label>
          </div>
          <div class="submit-btn">
            <button class="basic-btn">로그인</button>
<!--              <div id="testButton">testButton</div>-->
          </div>
          <?= csrf_input('memberLogin') ?>
        </form>
      </div>
    </div>
  </div>
</body>


<?php
include _SVC_INC_PATH_ ."/footer.php";
include _SVC_INC_PATH_ ."/footer_common.php"
?>

<script>
    jQuery(document.forms['auth_login']).on("submit",function(e){
        e.preventDefault();

        var formdata = new FormData(this);
        formdata.append("mode","memberLogin");

        ajax_form({
            url: "<?=_SVC_INC_URL_?>/common.ajax.php",
            type: "POST",
            data: formdata,
            success: function (data) {
                console.log(data);
                if (!data.code) {
                    kuls_alert(data.mesg);
                    return;
                }
                location.reload();
            },
            error: function (request, status, error) {
                kuls_alert(error.message);
            }
        });
    });


    //document.getElementById("testButton").addEventListener('click',function(e){
    //    // console.log("!!");
    //    const firstPassword = {mode : "firstPassword"}
    //
    //    ajax_form({
    //        url: "<?php //=_SVC_INC_URL_?>///common.ajax.php",
    //        type: "POST",
    //        data: JSON.stringify(firstPassword),
    //        success: function (data) {
    //            console.log(data);
    //            if (!data.code) {
    //                kuls_alert(data.mesg);
    //                return;
    //            }
    //            location.reload();
    //        },
    //        error: function (request, status, error) {
    //            kuls_alert(error.message);
    //        }
    //    });
    //});

</script>
