import 'package:flutter/material.dart';
import '../widgets/ict_ui.dart';

class ICTSchoolsPage extends StatelessWidget {
  const ICTSchoolsPage({super.key, required this.schools, required this.programs, required this.onAdd});
  final List<Map<String, dynamic>> schools;
  final List<Map<String, dynamic>> programs;
  final VoidCallback onAdd;

  @override
  Widget build(BuildContext context) => Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
    ICTPageHeading(title: 'School Directory', subtitle: 'Schools registered in the ICT Department', icon: Icons.account_balance_outlined, actionText: 'ADD SCHOOL', onAction: onAdd),
    const SizedBox(height: 16),
    Container(color: ictGreen, padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12), child: const Row(children: [
      Expanded(child: Text('SCHOOL', style: TextStyle(color: Colors.white, fontWeight: FontWeight.w800))),
      Text('PROGRAMS', style: TextStyle(color: Colors.white, fontWeight: FontWeight.w800)),
    ])),
    const SizedBox(height: 3),
    Expanded(child: schools.isEmpty
      ? const ICTEmptyState(text: 'There are no schools yet. Add a school to begin.')
      : ListView.separated(
          itemCount: schools.length,
          separatorBuilder: (_, __) => const SizedBox(height: 3),
          itemBuilder: (_, index) {
            final school = schools[index];
            final count = programs.where((p) => '${p['school_id']}' == '${school['id']}').length;
            return ICTRecordTile(
              icon: Icons.account_balance_outlined,
              title: ictText(school['school_name']),
              detail: 'School code: ${ictText(school['school_code'], 'Not set')}',
              trailing: '$count ${count == 1 ? 'PROGRAM' : 'PROGRAMS'}',
            );
          },
        )),
  ]);
}
