// 帳號登入
$("#btn_login").click(function() {
    var username = $('#username').val();
    var password = $('#password').val();

    var param_string = {
        username: username,
        password: password
    };   

    if (username == '' || password == '') {
        return;
    }

    $.ajax({
        type: 'POST',
        url: 'http://api.ptt.cx:8750/api/v1/login/access-token',
        data: param_string,
        success: function(data, textStatus, jqXHR) {
            console.log(data); // test

            // 將access_token寫入localStorage

            // 導頁進Dashboard介面
            Swal.fire({
                title: '登入成功',
                icon: 'success',
                confirmButtonColor: '#3085d6',
            });
            window.setTimeout(() => {
                window.location.href = 'index.html';
            }, 1500);
        }, error: function(jqXHR, textStatus, errorThrown) {
            Swal.fire({
                title: '注意',
                icon: 'error',
                text: '系統問題',
                confirmButtonColor: '#3085d6',
            });
            return false;
        }
    });

    return false;
});