import 'package:flutter/material.dart';
import '../../../../../core/services/it_support_service.dart';
import '../it_support_widgets.dart';

class ITSupportInboxPage extends StatelessWidget {
  const ITSupportInboxPage({super.key, required this.notices, required this.more,
    required this.onRefresh, required this.onLoadMore, required this.onOpen});
  final List<SupportJson> notices;
  final bool more;
  final Future<void> Function() onRefresh;
  final VoidCallback onLoadMore;
  final ValueChanged<SupportJson> onOpen;

  @override
  Widget build(BuildContext context) => RefreshIndicator(onRefresh: onRefresh,
    child: ListView.builder(physics: const AlwaysScrollableScrollPhysics(),
      padding: const EdgeInsets.fromLTRB(16, 4, 16, 85), itemCount: notices.length + 1,
      itemBuilder: (context, index) {
        if (index == notices.length) return Padding(padding: const EdgeInsets.all(24), child: Center(child: more
          ? TextButton(onPressed: onLoadMore, child: const Text('Load more'))
          : Text(notices.isEmpty ? 'Your IT updates will appear here.' : '${notices.length} updates loaded',
            textAlign: TextAlign.center, style: const TextStyle(color: Color(0xFF7A887F), fontSize: 12))));
        final notice = notices[index];
        return Padding(padding: const EdgeInsets.only(bottom: 7), child: Container(color: Colors.white,
          child: ListTile(leading: Icon(supportBool(notice['is_read']) ? Icons.notifications_none : Icons.notifications_active_outlined,
            color: supportGreen), title: Text('${notice['message']}', style: const TextStyle(color: supportInk, fontWeight: FontWeight.w600)),
            subtitle: Text('#${notice['ticket_id']} · ${notice['created_at']}'), onTap: () => onOpen(notice))));
      }));
}
