import React, { useState, useEffect } from 'react'; import { Card } from '../ui/card'; import { Button } from '../ui/button'; import { Input } from '../ui/input'; import { Recipe } from '../../recipe'; import { generateDeepLink } from '../ui/DeepLinkModal'; import Copy from '../icons/Copy'; import { Check } from 'lucide-react'; interface ScheduleFromRecipeModalProps { isOpen: boolean; onClose: () => void; recipe: Recipe; onCreateSchedule: (deepLink: string) => void; } export const ScheduleFromRecipeModal: React.FC = ({ isOpen, onClose, recipe, onCreateSchedule, }) => { const [copied, setCopied] = useState(false); const [deepLink, setDeepLink] = useState(''); useEffect(() => { if (isOpen && recipe) { // Convert Recipe to the format expected by generateDeepLink const recipeConfig = { id: recipe.title?.toLowerCase().replace(/[^a-z0-9-]/g, '-') || 'recipe', title: recipe.title, description: recipe.description, instructions: recipe.instructions, activities: recipe.activities || [], prompt: recipe.prompt, extensions: recipe.extensions, goosehints: recipe.goosehints, context: recipe.context, profile: recipe.profile, author: recipe.author, }; const link = generateDeepLink(recipeConfig); setDeepLink(link); } }, [isOpen, recipe]); const handleCopy = () => { navigator.clipboard .writeText(deepLink) .then(() => { setCopied(true); setTimeout(() => setCopied(false), 2000); }) .catch((err) => { console.error('Failed to copy the text:', err); }); }; const handleCreateSchedule = () => { onCreateSchedule(deepLink); onClose(); }; const handleClose = () => { setCopied(false); onClose(); }; if (!isOpen) return null; return (

Create Schedule from Recipe

Create a scheduled task using this recipe configuration.

Recipe Details:

{recipe.title}

{recipe.description}

This link contains your recipe configuration and can be used to create a schedule.

); };