import {Button,LinearProgress,Stack,TextField,Typography} from "@mui/material";import {useState} from "react";import type {Gallery_Performance_Capture} from "../protocol/gallery_types";
export function Capture_Toolbar({capture,on_capture}:{capture:Gallery_Performance_Capture;on_capture:(action:string,count?:number)=>void}) {const [capture_count_draft,set_capture_count_draft]=useState("20");const active=capture.sessions.find(session=>session.session_id===capture.controller.session_id)||capture.sessions.find(session=>session.active);const requested=active?.requested_count??0,captured=active?.captured_count??0;return <Stack spacing={1.5}><Stack direction="row" spacing={1}><Button variant="contained" disabled={capture.controller.enabled} onClick={()=>on_capture("capture_next_frame")}>Capture next frame</Button><TextField size="small" type="number" value={capture_count_draft} inputProps={{min:1,max:1000}} onChange={event=>set_capture_count_draft(event.target.value)} sx={{width:110}}/><Button variant="outlined" disabled={capture.controller.enabled} onClick={()=>on_capture("capture_frames",Math.max(1,Math.min(1000,Number(capture_count_draft)||20)))}>Capture N frames</Button></Stack><Typography variant="caption">{requested?`captured ${captured} / ${requested}`:"Capture disabled"}</Typography>{requested>0&&<LinearProgress variant="determinate" value={Math.min(100,captured/requested*100)}/>}</Stack>;}
