import React, { FormEvent, useRef } from "react" import { Button } from "./ui/button" import { useStore } from "@/lib/states" import { useClickAway, useToggle } from "react-use" import { Textarea } from "./ui/textarea" import { cn } from "@/lib/utils" const PromptInput = () => { const [ isProcessing, prompt, updateSettings, runInpainting, showPrevMask, hidePrevMask, ] = useStore((state) => [ state.getIsProcessing(), state.settings.prompt, state.updateSettings, state.runInpainting, state.showPrevMask, state.hidePrevMask, ]) const [showScroll, toggleShowScroll] = useToggle(false) const ref = useRef(null) useClickAway(ref, () => { if (ref?.current) { const input = ref.current as HTMLTextAreaElement input.blur() } }) const handleOnInput = (evt: FormEvent) => { evt.preventDefault() evt.stopPropagation() const target = evt.target as HTMLTextAreaElement updateSettings({ prompt: target.value }) } const handleRepaintClick = () => { if (!isProcessing) { runInpainting() } } const onKeyUp = (e: React.KeyboardEvent) => { if (e.key === "Enter" && e.ctrlKey && prompt.length !== 0) { handleRepaintClick() } } const onMouseEnter = () => { showPrevMask() } const onMouseLeave = () => { hidePrevMask() } return (