const video = document.getElementById('video');
const canvas = document.getElementById('canvas');
const inputFoto = document.getElementById('foto');

navigator.mediaDevices.getUserMedia({
    video: { facingMode: "user" },
    audio: false
}).then(stream => {
    video.srcObject = stream;
});

function tomarFoto() {
    canvas.width = video.videoWidth;
    canvas.height = video.videoHeight;

    const ctx = canvas.getContext('2d');
    ctx.drawImage(video, 0, 0);

    canvas.toBlob(blob => {
        const file = new File([blob], "foto.png", { type: "image/png" });
        const dt = new DataTransfer();
        dt.items.add(file);
        inputFoto.files = dt.files;
        alert("Foto lista ✅");
    });
}
