import 'package:flutter/material.dart';
import '../widgets/marketing_ui.dart';
import '../widgets/marketing_trend_chart.dart';
import 'marketing_page_common.dart';
class MarketingOverviewPage extends StatelessWidget {
 const MarketingOverviewPage({super.key,required this.summary,required this.trend,required this.centers,required this.onOpen});
 final Map<String,dynamic> summary; final List<Map<String,dynamic>> trend,centers; final ValueChanged<int> onOpen;
 @override Widget build(BuildContext context){final top=summary['top_center'] is Map?Map<String,dynamic>.from(summary['top_center']):<String,dynamic>{};return MarketingPageFrame(title:'Marketing Overview',subtitle:'Service network, student recruitment and monthly progress',icon:Icons.dashboard_outlined,children:[
  LayoutBuilder(builder:(context,c){final n=c.maxWidth<600?2:4;final w=(c.maxWidth-(n-1)*10)/n;return Wrap(spacing:10,runSpacing:10,children:[
   SizedBox(width:w,child:MarketingMetricCard(title:'Service centers',value:'${summary['service_center_count']??0}',icon:Icons.storefront_outlined)),SizedBox(width:w,child:MarketingMetricCard(title:'Active agents',value:'${summary['agent_count']??0}',icon:Icons.support_agent_outlined)),SizedBox(width:w,child:MarketingMetricCard(title:'Phones assigned',value:'${summary['phone_count']??0}',icon:Icons.phone_iphone_outlined)),SizedBox(width:w,child:MarketingMetricCard(title:'Students enrolled',value:'${summary['students_enrolled']??0}',icon:Icons.school_outlined))]);}),const SizedBox(height:12),
  SizedBox(height:260,child:MarketingTrendChart(rows:trend)),const SizedBox(height:12),
  if(top.isNotEmpty) marketingRecord(icon:Icons.emoji_events_outlined,title:'Top service center this month',detail:'${top['campus']??'Campus'} • ${top['students_enrolled']??0} students enrolled',tag:top['name']?.toString()),
  const SizedBox(height:12),Wrap(spacing:10,runSpacing:10,children:[_quick('Service centers',Icons.storefront_outlined,()=>onOpen(1)),_quick('Agents',Icons.support_agent_outlined,()=>onOpen(2)),_quick('Monthly performance',Icons.track_changes_outlined,()=>onOpen(4)),_quick('Monthly reports',Icons.summarize_outlined,()=>onOpen(6))])
 ]);}
 Widget _quick(String text,IconData icon,VoidCallback action)=>SizedBox(width:190,child:OutlinedButton.icon(onPressed:action,icon:Icon(icon),label:Text(text),style:OutlinedButton.styleFrom(foregroundColor:marketingGreen,shape:const RoundedRectangleBorder(borderRadius:BorderRadius.zero),side:const BorderSide(color:marketingLine),padding:const EdgeInsets.symmetric(horizontal:12,vertical:14))));
}
