import {Button,Paper,Stack,TextField,Typography} from "@mui/material";import {useState} from "react";import type {Gallery_Action,Json_Primitive} from "../protocol/gallery_types";
function Action_Row({action,on_action}:{action:Gallery_Action;on_action:(id:string,argument?:Json_Primitive)=>void}) {const [argument,set_argument]=useState(String(action.argument_default??""));return <Paper sx={{p:1.5,display:"flex",alignItems:"center",gap:1.5}}><Stack flex={1}><Typography fontWeight={700}>{action.label}</Typography><Typography variant="caption" fontFamily="monospace">{action.api}</Typography></Stack>{action.argument_input&&<TextField size="small" type={action.argument_input} value={argument} onChange={event=>set_argument(event.target.value)} sx={{width:130}}/>}<Button variant="contained" onClick={()=>on_action(action.id,action.argument_input==="number"?Number(argument):action.argument_input?argument:undefined)}>执行</Button></Paper>;}
export function Actions_Panel({actions,on_action}:{actions:Gallery_Action[];on_action:(id:string,argument?:Json_Primitive)=>void}) {return <Stack spacing={1}>{actions.map(action=><Action_Row key={action.id} action={action} on_action={on_action}/>)}</Stack>;}
