import { createChatEngine } from '@/api/chat-engines';
import { withCreateEntityForm } from '@/components/form/create-entity-form';
import { FormInput } from '@/components/form/control-widget';
import { useRouter } from 'next/navigation';
import startTransition, { useTransition } from 'react';
import { z } from 'zod';

const Form = withCreateEntityForm(z.object({
  name: z.string().min(1),
}), createChatEngine);

export function CreateChatEngineForm ({}: {}) {
  const [transitioning, startTransition] = useTransition();
  const router = useRouter();

  return (
    <Form
      transitioning={transitioning}
      onCreated={ce => {
        startTransition(() => {
          router.push(`/chat-engines/${ce.id}`);
          router.refresh();
        });
      }}
      defaultValues={{
        name: '',
      }}
    >
      <Form.Basic name="name" label="名称">
        <FormInput placeholder="" />
      </Form.Basic>
    </Form>
  );
}



