<?php

declare(strict_types=1);

namespace PpPhp\Core\Designer\Presets;

use PpPhp\Core\Designer\DesignerComponent as C;

class ExecutiveDashboardPreset implements DesignerPresetInterface
{
    public static function id(): string
    {
        return 'executive';
    }

    public static function name(): string
    {
        return 'Executive Dashboard';
    }

    public static function description(): string
    {
        return 'Executive level dashboard with KPIs, charts, insights, activity, and productivity widgets.';
    }

    public static function icon(): string
    {
        return 'speedometer2';
    }

    public static function category(): string
    {
        return 'Business';
    }

    public static function type(): string
    {
        return 'dashboard';
    }

    public static function components(): array
    {
        return [
            C::breadcrumb('breadcrumb_main', ['Home', 'Dashboard']),

            C::heading(
                'page_heading',
                'Executive Dashboard',
                'Monitor executive KPIs, insights, activity, and productivity.'
            ),

            self::executiveKpis(),
            self::quickActions(),
            self::operationalStats(),
            self::charts(),
            self::executiveInsights(),
            self::activityAndNotifications(),
            self::productivityWidgets(),
        ];
    }

    private static function executiveKpis(): array
    {
        return C::make('executive_kpi_section', 'section', 'Executive KPIs', [
            'title' => 'Executive KPIs',
            'collapsible' => true,
            'collapsed' => false,
        ], [
            C::make('executive_kpi_row', 'row', 'Executive KPI Row', [
                'columns' => 4,
                'cells' => [
                    self::kpiCell('revenue_kpi', 'Revenue', '$125,000', '14%', 'up', 'vs last month', 'cash-stack'),
                    self::kpiCell('customers_kpi', 'Customers', '3,420', '8%', 'up', 'new growth', 'people'),
                    self::kpiCell('orders_kpi', 'Orders', '1,284', '5%', 'up', 'this period', 'cart-check'),
                    self::kpiCell('returns_kpi', 'Returns', '32', '3%', 'down', 'lower than previous', 'arrow-return-left'),
                ],
            ]),
        ]);
    }

    private static function quickActions(): array
    {
        return C::make('dashboard_quick_actions', 'section', 'Quick Actions', [
            'title' => 'Quick Actions',
            'collapsible' => true,
            'collapsed' => false,
        ], [
            C::make('dashboard_quick_links', 'quick-links', 'Quick Links', [
                'links' => [
                    ['label' => 'Add Record', 'icon' => 'plus-circle'],
                    ['label' => 'Import Data', 'icon' => 'upload'],
                    ['label' => 'Export Data', 'icon' => 'download'],
                    ['label' => 'Settings', 'icon' => 'gear'],
                ],
            ]),
        ]);
    }

    private static function operationalStats(): array
    {
        return C::make('dashboard_stats_section', 'section', 'Operational Statistics', [
            'title' => 'Operational Statistics',
            'collapsible' => true,
            'collapsed' => false,
        ], [
            C::make('dashboard_stats_row', 'row', 'Operational Statistics Row', [
                'columns' => 4,
                'cells' => [
                    self::statCell('total_records_card', 'Total Records', '1,248', 'database', 3),
                    self::statCell('new_today_card', 'New Today', '32', 'plus-circle', 3),
                    self::statCell('pending_card', 'Pending', '18', 'hourglass-split', 3),
                    self::statCell('completed_card', 'Completed', '1,096', 'check-circle', 3),
                ],
            ]),
        ]);
    }

    private static function charts(): array
    {
        return C::make('dashboard_charts_section', 'section', 'Charts', [
            'title' => 'Charts',
            'collapsible' => true,
            'collapsed' => false,
        ], [
            C::make('dashboard_charts_row', 'row', 'Charts Row', [
                'columns' => 2,
                'cells' => [
                    [
                        'id' => 'records_chart_cell',
                        'span' => 6,
                        'components' => [
                            C::make('records_chart', 'chart', 'Records Chart', [
                                'title' => 'Records by Month',
                                'chartType' => 'bar',
                                'sample' => 'Monthly records overview',
                            ]),
                        ],
                        'style' => C::style(),
                    ],
                    [
                        'id' => 'status_chart_cell',
                        'span' => 6,
                        'components' => [
                            C::make('status_chart', 'chart', 'Status Chart', [
                                'title' => 'Status Distribution',
                                'chartType' => 'donut',
                                'sample' => 'Status distribution overview',
                            ]),
                        ],
                        'style' => C::style(),
                    ],
                ],
            ]),
        ]);
    }

    private static function executiveInsights(): array
    {
        return C::make('executive_insights_section', 'section', 'Executive Insights', [
            'title' => 'Executive Insights',
            'collapsible' => true,
            'collapsed' => false,
        ], [
            C::make('executive_insights_row', 'row', 'Executive Insights Row', [
                'columns' => 2,
                'cells' => [
                    self::miniTableCell('top_customers_table', 'Top Customers', 6),
                    [
                        'id' => 'executive_calendar_cell',
                        'span' => 6,
                        'components' => [
                            C::make('executive_calendar', 'calendar-widget', 'Executive Calendar', [
                                'title' => 'Executive Calendar',
                                'month' => 'June 2026',
                            ]),
                        ],
                        'style' => C::style(),
                    ],
                ],
            ]),
        ]);
    }

    private static function activityAndNotifications(): array
    {
        return C::make('dashboard_activity_section', 'section', 'Activity & Notifications', [
            'title' => 'Activity & Notifications',
            'collapsible' => true,
            'collapsed' => false,
        ], [
            C::make('dashboard_activity_row', 'row', 'Activity Row', [
                'columns' => 2,
                'cells' => [
                    [
                        'id' => 'recent_activity_cell',
                        'span' => 6,
                        'components' => [
                            C::make('recent_activity', 'recent-activity', 'Recent Activity', [
                                'items' => [
                                    ['title' => 'New record added', 'time' => '2 minutes ago', 'icon' => 'plus-circle'],
                                    ['title' => 'Record updated', 'time' => '15 minutes ago', 'icon' => 'pencil'],
                                    ['title' => 'Export completed', 'time' => '1 hour ago', 'icon' => 'download'],
                                ],
                            ]),
                        ],
                        'style' => C::style(),
                    ],
                    [
                        'id' => 'notifications_cell',
                        'span' => 6,
                        'components' => [
                            C::make('dashboard_notifications', 'notification-list', 'Notifications', [
                                'items' => [
                                    ['title' => '3 records require review', 'variant' => 'warning'],
                                    ['title' => 'Import completed successfully', 'variant' => 'success'],
                                    ['title' => 'Backup scheduled tonight', 'variant' => 'info'],
                                ],
                            ]),
                        ],
                        'style' => C::style(),
                    ],
                ],
            ]),
        ]);
    }

    private static function productivityWidgets(): array
    {
        return C::make('dashboard_productivity_section', 'section', 'Productivity Widgets', [
            'title' => 'Productivity Widgets',
            'collapsible' => true,
            'collapsed' => false,
        ], [
            C::make('dashboard_productivity_row', 'row', 'Productivity Row', [
                'columns' => 2,
                'cells' => [
                    [
                        'id' => 'task_list_cell',
                        'span' => 6,
                        'components' => [
                            C::make('dashboard_tasks', 'task-list', 'Task List', [
                                'tasks' => [
                                    ['title' => 'Review new records', 'due' => 'Today', 'done' => false],
                                    ['title' => 'Approve pending items', 'due' => 'Tomorrow', 'done' => false],
                                    ['title' => 'Export monthly report', 'due' => 'This week', 'done' => true],
                                ],
                            ]),
                        ],
                        'style' => C::style(),
                    ],
                    [
                        'id' => 'progress_card_cell',
                        'span' => 6,
                        'components' => [
                            C::make('dashboard_progress', 'progress-card', 'Monthly Progress', [
                                'label' => 'Monthly Progress',
                                'value' => 72,
                                'subtitle' => '72% of monthly target completed',
                            ]),
                        ],
                        'style' => C::style(),
                    ],
                ],
            ]),
        ]);
    }

    private static function statCell(string $id, string $label, string $value, string $icon, int $span): array
    {
        return [
            'id' => $id . '_cell',
            'span' => $span,
            'components' => [
                C::make($id, 'stat-card', $label, [
                    'label' => $label,
                    'value' => $value,
                    'icon' => $icon,
                ]),
            ],
            'style' => C::style(),
        ];
    }

    private static function kpiCell(
        string $id,
        string $label,
        string $value,
        string $trend,
        string $direction,
        string $subtitle,
        string $icon,
        int $span = 3
    ): array {
        return [
            'id' => $id . '_cell',
            'span' => $span,
            'components' => [
                C::make($id, 'kpi-trend-card', $label, [
                    'label' => $label,
                    'value' => $value,
                    'trend' => $trend,
                    'trendDirection' => $direction,
                    'subtitle' => $subtitle,
                    'icon' => $icon,
                ]),
            ],
            'style' => C::style(),
        ];
    }

    private static function miniTableCell(string $id, string $title, int $span = 6): array
    {
        return [
            'id' => $id . '_cell',
            'span' => $span,
            'components' => [
                C::make($id, 'mini-table', $title, [
                    'columns' => ['Name', 'Status', 'Amount'],
                    'rows' => [
                        ['Alpha Corp', 'Active', '$12,400'],
                        ['Beta Group', 'Pending', '$8,900'],
                        ['Gamma Ltd', 'Review', '$5,200'],
                    ],
                ]),
            ],
            'style' => C::style(),
        ];
    }
}
