import { AdminShell } from '../../../components/admin/admin-page.jsx';
import DefinitionEditor from './editor.jsx';

export const dynamic = 'force-dynamic';

const STARTER_SPEC = {
  schema_version: 1,
  slug: 'my-new-workflow',
  name: 'My new workflow',
  version: 1,
  status: 'draft',
  description: 'A short description of what this workflow accomplishes.',
  category: 'general',
  stages: [
    {
      slug: 'intake',
      name: 'Applicant intake',
      kind: 'intake_form',
      config: {
        form_schema: {
          title: 'Intake',
          description: 'Submit the applicant details.',
          fields: [
            { name: 'applicant_name', label: 'Applicant name', type: 'text', required: true },
            { name: 'email', label: 'Email', type: 'email', required: true },
          ],
        },
      },
    },
    {
      slug: 'completeness',
      name: 'Completeness check',
      kind: 'agent_run',
      config: {
        agent_template_slug: 'completeness-agent',
        prompt: 'Verify the intake payload is complete. Return strict JSON: { "outcome": "pass"|"needs_info", "missing_fields": [], "warnings": [], "summary": "..." }.',
        timeout_ms: 60000,
        on_outcome: { pass: 'final-package', needs_info: 'fail' },
      },
      on_pass_stage_slug: 'final-package',
      on_fail_stage_slug: null,
    },
    {
      slug: 'final-package',
      name: 'Final package',
      kind: 'package',
      config: {
        title_template: 'Package — {{intake.applicant_name}}',
        include_stages: ['intake', 'completeness'],
      },
    },
  ],
};

export default function NewDefinitionPage() {
  return (
    <AdminShell
      kicker="Workflows"
      title="New workflow"
      description="Paste or compose a JSON workflow spec. Validate inline, then publish — the engine reads it on the next case start. No code edit, no restart."
      hideProjectSwitcher
    >
      <div className="wf-editor-page" data-page="workflows-new-definition">
        <DefinitionEditor starterSpec={STARTER_SPEC} />
      </div>
    </AdminShell>
  );
}
