// lib/features/admin/tabs/library/book_view_dialog.dart

import 'package:flutter/material.dart';

const Color _standardGold = Color.fromARGB(255, 204, 117, 4);
const Color _darkGreen = Color.fromARGB(255, 2, 105, 48);

class BookViewDialog extends StatelessWidget {
  final Map<String, dynamic> book;

  const BookViewDialog({super.key, required this.book});

  @override
  Widget build(BuildContext context) {
    return Dialog(
      shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
      backgroundColor: Colors.white,
      child: Container(
        width: 450,
        decoration: BoxDecoration(
          border: Border.all(color: Colors.grey.shade300, width: 1),
        ),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            // --- HEADER ---
            Container(
              padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 20),
              decoration: const BoxDecoration(
                color: _darkGreen,
                border: Border(bottom: BorderSide(color: _standardGold, width: 4)),
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  const Text(
                    'BOOK DETAILS',
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: 16,
                      fontWeight: FontWeight.bold,
                      letterSpacing: 1.2,
                    ),
                  ),
                  IconButton(
                    onPressed: () => Navigator.of(context).pop(),
                    icon: const Icon(Icons.close_rounded, color: Colors.white),
                    splashRadius: 20,
                    padding: EdgeInsets.zero,
                    constraints: const BoxConstraints(),
                  ),
                ],
              ),
            ),
            
            // --- DETAILS BODY ---
            Padding(
              padding: const EdgeInsets.all(32.0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  _buildDetailRow('Book ID', book['id']?.toString() ?? 'N/A'),
                  const Divider(height: 32),
                  _buildDetailRow('Title', book['title']?.toString() ?? 'Unknown'),
                  const Divider(height: 32),
                  _buildDetailRow('Author', book['author']?.toString() ?? 'Unknown'),
                  const Divider(height: 32),
                  _buildDetailRow('Department', book['department']?.toString() ?? 'Unassigned'),
                  const Divider(height: 32),
                  _buildDetailRow('Status', book['status']?.toString() ?? 'Available', isStatus: true),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildDetailRow(String label, String value, {bool isStatus = false}) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        SizedBox(
          width: 120,
          child: Text(
            label.toUpperCase(),
            style: TextStyle(
              fontWeight: FontWeight.bold,
              color: Colors.grey.shade500,
              fontSize: 12,
              letterSpacing: 0.5,
            ),
          ),
        ),
        Expanded(
          child: Text(
            value,
            style: TextStyle(
              fontSize: 15,
              fontWeight: isStatus ? FontWeight.bold : FontWeight.w500,
              color: isStatus 
                  ? (value.toLowerCase() == 'available' ? Colors.green.shade700 : _standardGold)
                  : Colors.grey.shade800,
            ),
          ),
        ),
      ],
    );
  }
}