/*// lib/features/admin/tabs/faq/draft_faq_sub_tab.dart

import 'package:flutter/material.dart';

class DraftFaqSubTab extends StatefulWidget {
  const DraftFaqSubTab({super.key});

  @override
  State<DraftFaqSubTab> createState() => _DraftFaqSubTabState();
}

class _DraftFaqSubTabState extends State<DraftFaqSubTab> {
  static const Color _standardGold = Color.fromARGB(255, 204, 117, 4);
  static const Color _darkGreen = Color.fromARGB(255, 2, 105, 48);

  final List<Map<String, dynamic>> _faqs = [
    {
      'question': 'Where can I find the semester academic calendar?', 
      'answer': 'The calendar is available under the "Lectures" tab or on the main university website.', 
      'isVisible': false
    },
  ];

  void _showFaqFormDialog({int? index, Map<String, dynamic>? existingFaq}) {
    final isEditing = index != null && existingFaq != null;
    final formKey = GlobalKey<FormState>();
    final questionCtrl = TextEditingController(text: isEditing ? existingFaq['question'] : '');
    final answerCtrl = TextEditingController(text: isEditing ? existingFaq['answer'] : '');
    bool isVisibleStatus = isEditing ? existingFaq['isVisible'] : false;

    showDialog(
      context: context,
      barrierDismissible: false,
      builder: (ctx) => StatefulBuilder(
        builder: (context, setDialogState) {
          return AlertDialog(
            shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
            backgroundColor: Colors.white,
            title: Text(
              isEditing ? 'Edit Draft FAQ' : 'Add New Draft FAQ', 
              style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 18)
            ),
            content: SizedBox(
              width: 500,
              child: Form(
                key: formKey,
                child: SingleChildScrollView(
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      _buildFlatTextField(
                        controller: questionCtrl,
                        label: 'Question',
                        icon: Icons.help_outline_rounded,
                        validator: (value) => value!.trim().isEmpty ? 'Question is required' : null,
                      ),
                      const SizedBox(height: 16),
                      _buildFlatTextField(
                        controller: answerCtrl,
                        label: 'Answer',
                        icon: Icons.question_answer_outlined,
                        maxLines: 4,
                        validator: (value) => value!.trim().isEmpty ? 'Answer is required' : null,
                      ),
                      const SizedBox(height: 16),
                      SwitchListTile(
                        contentPadding: EdgeInsets.zero,
                        title: const Text('Publish Immediately', style: TextStyle(fontWeight: FontWeight.w600, fontSize: 14)),
                        subtitle: Text(
                          isVisibleStatus ? 'Students will see this FAQ.' : 'Saved as a hidden draft.',
                          style: TextStyle(fontSize: 12, color: Colors.grey.shade600),
                        ),
                        activeThumbColor: Colors.white,
                        activeTrackColor: _darkGreen,
                        value: isVisibleStatus,
                        onChanged: (bool value) {
                          setDialogState(() => isVisibleStatus = value);
                        },
                      )
                    ],
                  ),
                ),
              ),
            ),
            actionsPadding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
            actions: [
              TextButton(
                onPressed: () => Navigator.pop(ctx),
                child: Text('CANCEL', style: TextStyle(color: Colors.grey.shade600, fontWeight: FontWeight.bold)),
              ),
              ElevatedButton(
                style: ElevatedButton.styleFrom(
                  backgroundColor: _darkGreen,
                  foregroundColor: Colors.white,
                  elevation: 0,
                  shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)),
                ),
                onPressed: () {
                  if (formKey.currentState!.validate()) {
                    setState(() {
                      if (isEditing) {
                        if (isVisibleStatus) {
                          _faqs.removeAt(index); // Moved to published conceptually
                        } else {
                          _faqs[index] = {
                            'question': questionCtrl.text.trim(),
                            'answer': answerCtrl.text.trim(),
                            'isVisible': false,
                          };
                        }
                      } else {
                        if (!isVisibleStatus) {
                          _faqs.insert(0, {
                            'question': questionCtrl.text.trim(),
                            'answer': answerCtrl.text.trim(),
                            'isVisible': false,
                          });
                        }
                      }
                    });
                    Navigator.pop(ctx);
                    _showSnackBar(isEditing ? 'Draft updated.' : 'Draft saved.', _darkGreen);
                  }
                },
                child: Text(isEditing ? 'SAVE CHANGES' : 'ADD DRAFT'),
              ),
            ],
          );
        }
      ),
    );
  }

  void _confirmDelete(int index) {
    showDialog(
      context: context,
      builder: (ctx) => AlertDialog(
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)),
        backgroundColor: Colors.white,
        title: Row(
          children: [
            const Icon(Icons.warning_amber_rounded, color: Colors.redAccent),
            const SizedBox(width: 8),
            const Text('Delete FAQ', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18)),
          ],
        ),
        content: Text(
          'Are you sure you want to delete this FAQ? This action cannot be undone.',
          style: TextStyle(color: Colors.grey.shade800),
        ),
        actions: [
          TextButton(
            onPressed: () => Navigator.pop(ctx),
            child: Text('CANCEL', style: TextStyle(color: Colors.grey.shade600, fontWeight: FontWeight.bold)),
          ),
          ElevatedButton(
            style: ElevatedButton.styleFrom(
              backgroundColor: Colors.redAccent,
              foregroundColor: Colors.white,
              elevation: 0,
              shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)),
            ),
            onPressed: () {
              setState(() => _faqs.removeAt(index));
              Navigator.pop(ctx);
              _showSnackBar('Draft has been deleted.', Colors.black87);
            },
            child: const Text('DELETE'),
          ),
        ],
      ),
    );
  }

  void _toggleVisibility(int index) {
    setState(() {
      _faqs.removeAt(index);
    });
    _showSnackBar('FAQ is now published to students.', _darkGreen);
  }

  void _showSnackBar(String message, Color color) {
    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(
        content: Text(message, style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
        backgroundColor: color,
        behavior: SnackBarBehavior.floating,
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.transparent,
      floatingActionButton: FloatingActionButton.extended(
        onPressed: () => _showFaqFormDialog(),
        backgroundColor: Colors.grey.shade800,
        elevation: 4,
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
        icon: const Icon(Icons.add_rounded, color: Colors.white),
        label: const Text('NEW DRAFT', style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, letterSpacing: 1.0)),
      ),
      body: SingleChildScrollView(
        padding: const EdgeInsets.all(32.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            const Text(
              'Drafts & Hidden FAQs',
              style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold, color: Colors.black87),
            ),
            const SizedBox(height: 8),
            Text(
              'These questions are currently hidden from students.',
              style: TextStyle(fontSize: 14, color: Colors.grey.shade600),
            ),
            const SizedBox(height: 32),

            if (_faqs.isEmpty)
              _buildEmptyState()
            else
              ListView.builder(
                shrinkWrap: true,
                physics: const NeverScrollableScrollPhysics(),
                itemCount: _faqs.length,
                itemBuilder: (context, index) {
                  final faq = _faqs[index];

                  return Container(
                    margin: const EdgeInsets.only(bottom: 16),
                    decoration: BoxDecoration(
                      color: Colors.white,
                      border: Border.all(color: Colors.grey.shade300, width: 1), 
                      borderRadius: BorderRadius.circular(8),
                      boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.02), blurRadius: 8, offset: const Offset(0, 4))],
                    ),
                    child: Theme(
                      data: Theme.of(context).copyWith(dividerColor: Colors.transparent), 
                      child: ExpansionTile(
                        iconColor: Colors.orange,
                        collapsedIconColor: Colors.grey.shade600,
                        title: Text(
                          faq['question'], 
                          style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16, color: Colors.grey.shade600)
                        ),
                        subtitle: Padding(
                          padding: const EdgeInsets.only(top: 4.0),
                          child: Row(
                            children: [
                              Container(width: 8, height: 8, decoration: const BoxDecoration(color: Colors.orange, shape: BoxShape.circle)),
                              const SizedBox(width: 6),
                              const Text('Hidden (Draft)', style: TextStyle(color: Colors.orange, fontSize: 12, fontWeight: FontWeight.w600)),
                            ],
                          ),
                        ),
                        children: [
                          Padding(
                            padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Divider(color: Colors.grey.shade200, height: 1, thickness: 1),
                                const SizedBox(height: 16),
                                Text(
                                  faq['answer'], 
                                  style: TextStyle(color: Colors.grey.shade800, height: 1.6, fontSize: 14)
                                ),
                                const SizedBox(height: 24),
                                Row(
                                  mainAxisAlignment: MainAxisAlignment.end,
                                  children: [
                                    TextButton.icon(
                                      onPressed: () => _toggleVisibility(index),
                                      icon: const Icon(Icons.public_rounded, color: _darkGreen, size: 18),
                                      label: const Text('Publish FAQ', style: TextStyle(color: _darkGreen, fontWeight: FontWeight.w600)),
                                    ),
                                    const SizedBox(width: 8),
                                    TextButton.icon(
                                      onPressed: () => _showFaqFormDialog(index: index, existingFaq: faq),
                                      icon: const Icon(Icons.edit_outlined, color: Colors.blueAccent, size: 18),
                                      label: const Text('Edit', style: TextStyle(color: Colors.blueAccent, fontWeight: FontWeight.w600)),
                                    ),
                                    const SizedBox(width: 8),
                                    TextButton.icon(
                                      onPressed: () => _confirmDelete(index),
                                      icon: const Icon(Icons.delete_outline, color: Colors.redAccent, size: 18),
                                      label: const Text('Delete', style: TextStyle(color: Colors.redAccent, fontWeight: FontWeight.w600)),
                                    ),
                                  ],
                                )
                              ],
                            ),
                          )
                        ],
                      ),
                    ),
                  );
                },
              ),
          ],
        ),
      ),
    );
  }

  Widget _buildEmptyState() {
    return Container(
      width: double.infinity,
      padding: const EdgeInsets.symmetric(vertical: 64),
      decoration: BoxDecoration(
        color: Colors.grey.shade50,
        borderRadius: BorderRadius.circular(8),
        border: Border.all(color: Colors.grey.shade200, width: 1),
      ),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Icon(Icons.edit_document, size: 48, color: Colors.grey.shade400),
          const SizedBox(height: 16),
          Text('No Drafts', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Colors.grey.shade800)),
          const SizedBox(height: 8),
          Text('There are currently no hidden or draft FAQs.', style: TextStyle(color: Colors.grey.shade600)),
        ],
      ),
    );
  }

  Widget _buildFlatTextField({required TextEditingController controller, required String label, required IconData icon, int maxLines = 1, String? Function(String?)? validator}) {
    return TextFormField(
      controller: controller, maxLines: maxLines, validator: validator, cursorColor: _darkGreen,
      decoration: InputDecoration(
        alignLabelWithHint: true, labelText: label, labelStyle: TextStyle(color: Colors.grey.shade600),
        prefixIcon: Padding(padding: EdgeInsets.only(bottom: maxLines > 1 ? (maxLines * 16.0) - 24 : 0), child: Icon(icon, color: Colors.grey.shade500, size: 20)),
        filled: true, fillColor: Colors.grey.shade50, contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
        border: OutlineInputBorder(borderRadius: BorderRadius.circular(4), borderSide: BorderSide(color: Colors.grey.shade300)),
        enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(4), borderSide: BorderSide(color: Colors.grey.shade300)),
        focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(4), borderSide: const BorderSide(color: _darkGreen, width: 2)),
        errorBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(4), borderSide: const BorderSide(color: Colors.redAccent)),
      ),
    );
  }
}*/