// frontend/components/automation/NewView.tsx — auto.jsx NewView 이식 (자연어 → 규칙) "use client"; import { useEffect, useRef, useState } from "react"; import { Icon } from "@/components/Icon"; import type { ParsePreview } from "@/lib/types"; import { AU_CAT, AU_TONE, Flow } from "./Flow"; // 원본 auto-data.js examples 입력 문장(고정 골든 — 칩 표시·정확 일치 트리거) const EXAMPLE_TEXTS = [ "출장 전날엔 저녁 일정 비워줘", "뉴스레터는 모아서 저녁에 보여줘", "운동을 3일 거르면 산책 잡아줘", ]; export function NewView({ parse, onCreate, }: { parse: (text: string) => Promise; onCreate: (p: ParsePreview) => void; }) { const [text, setText] = useState(""); const [preview, setPreview] = useState(null); const timer = useRef | null>(null); useEffect(() => { const t = text.trim(); if (!t) { setPreview(null); return; } if (timer.current) clearTimeout(timer.current); timer.current = setTimeout(async () => { try { const pr = await parse(t); setPreview(pr.matched ? pr : null); } catch { setPreview(null); } }, 300); return () => { if (timer.current) clearTimeout(timer.current); }; }, [text, parse]); const match = preview?.matched ? preview : null; return (
새 자동화 만들기

하고 싶은 일을 한 문장으로 적으세요. 트리거·조건·동작은 아리가 찾아요.

setText(e.target.value)} onKeyDown={(e) => { if (e.key === "Enter" && match) onCreate(match); }} placeholder="예: 출장 전날엔 저녁 일정 비워줘" aria-label="새 규칙 문장" autoFocus />
{EXAMPLE_TEXTS.map((t) => ( ))}
{/* 미리보기 */}

미리보기

{match ? "아리가 이렇게 이해했어요" : "문장을 적으면 여기에 규칙이 그려져요"}
{match && ( {AU_CAT[match.cat]} )}
{match ? ( <>
{match.name}
만든 규칙은 ‘내 규칙’에서 언제든 끄거나 지울 수 있어요.
) : (

예시 문장을 누르거나 직접 적어보세요. 아리가 트리거 → 조건 → 동작으로 나눠 보여드려요.

)}
); }