"use client";

import "./style.css";

import { MessageLang } from "@/lang/component/client";

export default function SignIn() {
    const FormSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
        e.preventDefault();

        const res = await fetch("/api/signin", {
            method: "POST",
            headers: {
                "Content-Type": "application/json",
            },
            body: JSON.stringify({
                email: e.currentTarget.email.value,
                password: e.currentTarget.password.value,
            }),
        });
        const data = await res.text();
        const json = JSON.parse(data);

        if (json.status === "success") {
            window.location.href = "/";
        }
    }

    return (
        <form onSubmit={FormSubmit}>
            <h1 className="title"><MessageLang text="Signin" /></h1>

            <label className="label"><MessageLang text="email" /></label>
            <input type="email" name="email" className="input" required />

            <br />

            <label className="label"><MessageLang text="password" /></label>
            <input type="password" name="password" className="input" required />

            <br />

            <button type="submit" className="button"><MessageLang text="Signin" /></button>
        </form>
    )
}