import { useEffect, useState, lazy, Suspense } from "react"; import { Link, useNavigate } from "react-router"; import PageMeta from "../../components/common/PageMeta"; import ComponentCard from "../../components/common/ComponentCard"; import { ProgressBar } from "../../components/ui/progress"; import { ApexOptions } from "apexcharts"; import EnhancedMetricCard from "../../components/dashboard/EnhancedMetricCard"; import PageHeader from "../../components/common/PageHeader"; const Chart = lazy(() => import("react-apexcharts").then((mod) => ({ default: mod.default }))); import { BoltIcon, ClockIcon, CheckCircleIcon, ArrowRightIcon, CalendarIcon, ListIcon, GroupIcon, FileTextIcon, ArrowUpIcon, ArrowDownIcon, PaperPlaneIcon, CloseIcon, FileIcon, } from "../../icons"; import { useSiteStore } from "../../store/siteStore"; import { useSectorStore } from "../../store/sectorStore"; interface AutomationStats { activeWorkflows: number; scheduledTasks: number; completedToday: number; successRate: number; automationCoverage: { keywords: boolean; clustering: boolean; ideas: boolean; tasks: boolean; content: boolean; images: boolean; publishing: boolean; }; recentActivity: Array<{ id: number; type: string; status: string; timestamp: Date; itemsProcessed: number; }>; } export default function AutomationDashboard() { const navigate = useNavigate(); const { activeSite } = useSiteStore(); const { activeSector } = useSectorStore(); const [stats, setStats] = useState(null); const [loading, setLoading] = useState(true); const [lastUpdated, setLastUpdated] = useState(new Date()); // Mock data for now - will be replaced with real API calls useEffect(() => { const fetchData = async () => { setLoading(true); // Simulate API call await new Promise((resolve) => setTimeout(resolve, 500)); setStats({ activeWorkflows: 3, scheduledTasks: 12, completedToday: 47, successRate: 94.5, automationCoverage: { keywords: true, clustering: true, ideas: true, tasks: false, content: true, images: true, publishing: false, }, recentActivity: [ { id: 1, type: "Content Generation", status: "completed", timestamp: new Date(Date.now() - 15 * 60 * 1000), itemsProcessed: 5, }, { id: 2, type: "Image Generation", status: "completed", timestamp: new Date(Date.now() - 45 * 60 * 1000), itemsProcessed: 8, }, { id: 3, type: "Keyword Clustering", status: "completed", timestamp: new Date(Date.now() - 2 * 60 * 60 * 1000), itemsProcessed: 12, }, ], }); setLastUpdated(new Date()); setLoading(false); }; fetchData(); }, [activeSite, activeSector]); const automationWorkflows = [ { id: 1, name: "Full Pipeline Automation", description: "Keywords → Clusters → Ideas → Tasks → Content → Images → Publish", status: "active", schedule: "Every 6 hours", lastRun: "2 hours ago", nextRun: "4 hours", coverage: 85, icon: PaperPlaneIcon, color: "from-[var(--igny8-purple)] to-[var(--igny8-purple-dark)]", }, { id: 2, name: "Writer Workflow", description: "Tasks → Content → Images → Publishing", status: "active", schedule: "Every 3 hours", lastRun: "1 hour ago", nextRun: "2 hours", coverage: 92, icon: FileTextIcon, color: "from-[var(--igny8-green)] to-[var(--igny8-green-dark)]", }, { id: 3, name: "Planner Workflow", description: "Keywords → Clusters → Ideas", status: "active", schedule: "Every 6 hours", lastRun: "3 hours ago", nextRun: "3 hours", coverage: 78, icon: ListIcon, color: "from-[var(--igny8-blue)] to-[var(--igny8-blue-dark)]", }, ]; const automationSteps = [ { step: "Keywords", enabled: true, description: "Auto-add keywords from opportunities", path: "/planner/keyword-opportunities", icon: ListIcon, }, { step: "Clustering", enabled: true, description: "Auto-cluster keywords into groups", path: "/planner/clusters", icon: GroupIcon, }, { step: "Ideas", enabled: true, description: "Auto-generate content ideas from clusters", path: "/planner/ideas", icon: BoltIcon, }, { step: "Tasks", enabled: false, description: "Auto-create tasks from ideas", path: "/writer/tasks", icon: CheckCircleIcon, }, { step: "Content", enabled: true, description: "Auto-generate content from tasks", path: "/writer/content", icon: FileTextIcon, }, { step: "Images", enabled: true, description: "Auto-generate images for content", path: "/writer/images", icon: FileIcon, }, { step: "Publishing", enabled: false, description: "Auto-publish content to WordPress", path: "/writer/published", icon: PaperPlaneIcon, }, ]; const chartOptions: ApexOptions = { chart: { type: "line", height: 300, toolbar: { show: false }, zoom: { enabled: false }, }, stroke: { curve: "smooth", width: 3, }, xaxis: { categories: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"], labels: { style: { colors: "#6b7280" } }, }, yaxis: { labels: { style: { colors: "#6b7280" } }, }, legend: { position: "top", labels: { colors: "#6b7280" }, }, colors: ["var(--igny8-blue)", "var(--igny8-green)", "var(--igny8-purple)"], grid: { borderColor: "#e5e7eb", }, }; const chartSeries = [ { name: "Automated", data: [12, 19, 15, 25, 22, 18, 24], }, { name: "Manual", data: [5, 8, 6, 10, 9, 7, 11], }, { name: "Failed", data: [1, 2, 1, 2, 1, 2, 1], }, ]; return ( <>
{/* Key Metrics */}
} trend={0} accentColor="purple" /> } trend={0} accentColor="blue" /> } trend={0} accentColor="green" /> } trend={0} accentColor="orange" />
{/* Automation Workflows */}
{automationWorkflows.map((workflow) => { const Icon = workflow.icon; return (
{workflow.status}

{workflow.name}

{workflow.description}

Schedule: {workflow.schedule}
Last Run: {workflow.lastRun}
Next Run: {workflow.nextRun}
Coverage {workflow.coverage}%
); })}
{/* Automation Steps Configuration */}
{automationSteps.map((step, index) => { const Icon = step.icon; const isEnabled = stats?.automationCoverage[step.step.toLowerCase() as keyof typeof stats.automationCoverage] || false; return (
{isEnabled && }

{step.step}

{step.description}

Configure
); })}
{/* Activity Chart */}
Loading chart...
}> {/* Recent Activity */}
{stats?.recentActivity.map((activity) => (

{activity.type}

{activity.status}
{activity.itemsProcessed} items processed {new Date(activity.timestamp).toLocaleTimeString()}
))}
{/* Quick Actions */}
); }