import './Bouton.css'
import {useState} from "react";

import {Status} from "../types";

function Bouton({arduinoStatus} : Status) {

    const [status, setStatus] = useState(!arduinoStatus?.locked || true)

    function changeStatus() {
        setStatus(!status)
        const toFetch = status ? 'http://localhost:3000/lock' : 'http://localhost:3000/unlock'
        fetch(toFetch, {method: 'POST'})
    }

    return(
        <div className="btn">
            <button onClick={changeStatus}>
                Chatière {status ? "ouverte" : "fermée"}
            </button>
        </div>
    )
}

export default Bouton
