| 1 | import React from "react"; |
| 2 | import { Button } from "../ui"; |
| 3 | import { RuleTemplateChip } from "./RuleTemplateChip"; |
| 4 | import { RuleTemplate, ruleTemplates } from "./ruleTemplates"; |
| 5 | |
| 6 | interface InputScreenProps { |
| 7 | inputPrompt: string; |
| 8 | onInputChange: (prompt: string) => void; |
| 9 | onGenerate: (prompt: string) => void; |
| 10 | onCancel: () => void; |
| 11 | onManualWrite: () => void; |
| 12 | } |
| 13 | |
| 14 | export function InputScreen({ |
| 15 | inputPrompt, |
| 16 | onInputChange, |
| 17 | onGenerate, |
| 18 | onCancel, |
| 19 | onManualWrite, |
| 20 | }: InputScreenProps) { |
| 21 | const handleSubmit = (e: React.FormEvent) => { |
| 22 | e.preventDefault(); |
| 23 | |
| 24 | if (!inputPrompt.trim()) { |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | onGenerate(inputPrompt); |
| 29 | }; |
| 30 | |
| 31 | const handleRuleTemplateClick = (template: RuleTemplate) => { |
| 32 | onInputChange(template.template); |
| 33 | }; |
| 34 | |
| 35 | return ( |
| 36 | <div className="px-2 pb-2 pt-4 sm:px-4"> |
| 37 | <div> |
| 38 | <div className="text-center"> |
| 39 | <h2 className="mb-0">Generate Rule</h2> |
| 40 | <p className="text-description m-0 mt-2 p-0"> |
| 41 | This will generate a new rule using the content of your chat history |
| 42 | </p> |
| 43 | </div> |
| 44 | <div className="mt-5"> |
| 45 | <form onSubmit={handleSubmit} className="flex flex-col gap-1"> |
| 46 | <div className="mb-2 flex flex-wrap items-center justify-center gap-x-3"> |
| 47 | {ruleTemplates.map((template, index) => ( |
| 48 | <RuleTemplateChip |
| 49 | key={index} |
| 50 | icon={template.icon} |
| 51 | text={template.title} |
| 52 | onClick={() => handleRuleTemplateClick(template)} |
| 53 | /> |
| 54 | ))} |
| 55 | </div> |
| 56 | |
| 57 | <div className="flex flex-col gap-2"> |
| 58 | <textarea |
| 59 | className="border-input-border bg-input text-input-foreground placeholder:text-input-placeholder focus:border-border-focus box-border w-full resize-none rounded border p-2 text-xs focus:outline-none" |
| 60 | placeholder="Describe your rule..." |
| 61 | rows={5} |
| 62 | value={inputPrompt} |
| 63 | onChange={(e) => onInputChange(e.target.value)} |
| 64 | /> |
| 65 | </div> |
| 66 | |
| 67 | <div className="my-4 flex flex-col items-center gap-2"> |
| 68 | <div className="flex flex-row justify-center gap-3"> |
| 69 | <Button |
| 70 | type="button" |
| 71 | className="min-w-16" |
| 72 | onClick={onCancel} |
| 73 | variant="outline" |
| 74 | > |
| 75 | Cancel |
| 76 | </Button> |
| 77 | <Button className="min-w-16" disabled={!inputPrompt.trim()}> |
| 78 | Generate |
| 79 | </Button> |
| 80 | </div> |
| 81 | <span |
| 82 | className="text-description cursor-pointer text-xs underline" |
| 83 | onClick={onManualWrite} |
| 84 | > |
| 85 | Or, write a rule from scratch |
| 86 | </span> |
| 87 | </div> |
| 88 | </form> |
| 89 | </div> |
| 90 | </div> |
| 91 | </div> |
| 92 | ); |
| 93 | } |