import { SUCCESS } from '../constants/index.js';

export default class Auth {
    static _token_name = "X-Token";

    async login({login, password}) {
        const info = { "Login": login, "Password": password };
        $.ajax({
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            type: "POST",
            url: "../api/auth",
            data: JSON.stringify(info),
            success: function (data, textStatus, jqXHR) {
                if (textStatus === SUCCESS) {
                    window.location.replace("index.html");
                }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                console.log(jqXHR.statusText);
            }
        });
    };

    static Logout() {
        localStorage.removeItem(this._token_name);
        window.location.replace("login.html");
    };
}