// lib/features/admin/tabs/messages/whatsapp_empty_state.dart

import 'package:flutter/material.dart';

class WhatsAppEmptyState extends StatelessWidget {
  final VoidCallback? onAskRockAI;

  const WhatsAppEmptyState({super.key, this.onAskRockAI});

  static const Color _green = Color.fromARGB(255, 2, 105, 48);
  static const Color _gold = Color.fromARGB(255, 204, 117, 4);
  static const Color _ink = Color(0xFF17231C);
  static const Color _muted = Color(0xFF66756C);
  static const Color _border = Color(0xFFE0E8E3);

  Widget _quickAction({
    required IconData icon,
    required String label,
    required String description,
    required Color accent,
    VoidCallback? onTap,
  }) {
    return ConstrainedBox(
      constraints: const BoxConstraints(minWidth: 150, maxWidth: 210),
      child: Material(
        color: Colors.transparent,
        child: InkWell(
          onTap: onTap,
          borderRadius: BorderRadius.circular(18),
          child: Container(
            padding: const EdgeInsets.all(16),
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.circular(18),
              border: Border.all(color: _border),
            ),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Container(
                  width: 48,
                  height: 48,
                  decoration: BoxDecoration(
                    color: accent.withOpacity(.09),
                    borderRadius: BorderRadius.circular(14),
                  ),
                  child: Icon(icon, color: accent, size: 24),
                ),
                const SizedBox(height: 12),
                Text(
                  label,
                  textAlign: TextAlign.center,
                  style: const TextStyle(
                    color: _ink,
                    fontSize: 14,
                    fontWeight: FontWeight.w800,
                  ),
                ),
                const SizedBox(height: 5),
                Text(
                  description,
                  textAlign: TextAlign.center,
                  maxLines: 2,
                  overflow: TextOverflow.ellipsis,
                  style: const TextStyle(
                    color: _muted,
                    fontSize: 11.5,
                    height: 1.35,
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return ColoredBox(
      color: const Color(0xFFF5F7F6),
      child: LayoutBuilder(
        builder: (context, constraints) {
          final compact = constraints.maxWidth < 620;
          final horizontal = compact ? 18.0 : 36.0;

          return SingleChildScrollView(
            physics: const BouncingScrollPhysics(),
            padding: EdgeInsets.symmetric(horizontal: horizontal, vertical: 28),
            child: ConstrainedBox(
              constraints: BoxConstraints(
                minHeight: (constraints.maxHeight - 56).clamp(0.0, double.infinity).toDouble(),
              ),
              child: Center(
                child: ConstrainedBox(
                  constraints: const BoxConstraints(maxWidth: 760),
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Container(
                        width: compact ? 74 : 88,
                        height: compact ? 74 : 88,
                        decoration: BoxDecoration(
                          gradient: const LinearGradient(
                            colors: [_green, Color(0xFF0A7C48)],
                            begin: Alignment.topLeft,
                            end: Alignment.bottomRight,
                          ),
                          borderRadius: BorderRadius.circular(compact ? 22 : 26),
                          boxShadow: [
                            BoxShadow(
                              color: _green.withOpacity(.18),
                              blurRadius: 26,
                              offset: const Offset(0, 10),
                            ),
                          ],
                        ),
                        child: const Icon(
                          Icons.forum_rounded,
                          color: Colors.white,
                          size: 40,
                        ),
                      ),
                      const SizedBox(height: 22),
                      Text(
                        'Connect Messages',
                        textAlign: TextAlign.center,
                        style: TextStyle(
                          color: _ink,
                          fontSize: compact ? 23 : 29,
                          fontWeight: FontWeight.w900,
                          letterSpacing: -.4,
                        ),
                      ),
                      const SizedBox(height: 9),
                      const Text(
                        'Select a conversation to continue chatting, or use one of the Rockview communication tools below.',
                        textAlign: TextAlign.center,
                        style: TextStyle(
                          color: _muted,
                          fontSize: 13,
                          height: 1.5,
                        ),
                      ),
                      const SizedBox(height: 26),
                      Wrap(
                        alignment: WrapAlignment.center,
                        spacing: 12,
                        runSpacing: 12,
                        children: [
                          _quickAction(
                            icon: Icons.description_outlined,
                            label: 'Share documents',
                            description: 'Send files inside an active conversation.',
                            accent: _green,
                          ),
                          _quickAction(
                            icon: Icons.person_add_alt_1_rounded,
                            label: 'Find a contact',
                            description: 'Use the chat list to start a conversation.',
                            accent: _gold,
                          ),
                          _quickAction(
                            icon: Icons.auto_awesome_rounded,
                            label: 'Ask Rock AI',
                            description: 'Get quick help with the Rockview system.',
                            accent: _green,
                            onTap: onAskRockAI,
                          ),
                        ],
                      ),
                      const SizedBox(height: 28),
                      Container(
                        padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 9),
                        decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.circular(30),
                          border: Border.all(color: _border),
                        ),
                        child: const Row(
                          mainAxisSize: MainAxisSize.min,
                          children: [
                            Icon(Icons.cloud_done_outlined, size: 17, color: _green),
                            SizedBox(width: 7),
                            Flexible(
                              child: Text(
                                'Live conversations stay synchronized through Firebase',
                                textAlign: TextAlign.center,
                                style: TextStyle(
                                  color: _muted,
                                  fontSize: 11.5,
                                  fontWeight: FontWeight.w600,
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ),
          );
        },
      ),
    );
  }
}
