import { useState } from 'react' import { X } from 'lucide-react' import { cn } from '@/lib/utils' import { StepForm } from './StepForm' import { StepLibraryBrowser } from './StepLibraryBrowser' import type { Step, StepCreate } from '@/types/step' export interface CustomStepDraft { title: string step_type: 'decision' | 'action' | 'solution' content: { instructions: string help_text?: string commands?: Array<{ label: string command: string command_type?: string }> } category_id?: string tags?: string[] } interface CustomStepModalProps { isOpen: boolean onClose: () => void onInsertStep: (step: Step | CustomStepDraft, isFromLibrary: boolean) => void } type Tab = 'create' | 'browse' export function CustomStepModal({ isOpen, onClose, onInsertStep }: CustomStepModalProps) { const [activeTab, setActiveTab] = useState('create') const [isSubmitting, setIsSubmitting] = useState(false) const [error, setError] = useState(null) if (!isOpen) return null const handleFormSubmit = async (data: StepCreate) => { setIsSubmitting(true) setError(null) try { // Always create a draft - saving to library is handled by PostStepActionModal const draft: CustomStepDraft = { title: data.title, step_type: data.step_type, content: data.content, category_id: data.category_id, tags: data.tags } onInsertStep(draft, false) // false = not from library (user typed it) } catch (err) { console.error('Failed to create step:', err) setError('Failed to create step. Please try again.') setIsSubmitting(false) } } const handleBrowserInsert = (step: Step) => { onInsertStep(step, true) // true = from library (already saved) } return (
{/* Header */}

Add Custom Step

{/* Tabs */}
{/* Error Display */} {error && (
{error}
)} {/* Tab Content */}
{activeTab === 'create' ? (
) : ( )}
{/* Loading Overlay */} {isSubmitting && (

Creating step...

)}
) }