'use client';

import React, { useState } from 'react';
import { useBulkSelection } from './context/BulkSelectionContext';
import { CheckCircle, XCircle, Edit, Trash2, X, ChevronUp, MoreHorizontal, Layers, ShieldCheck, AlertTriangle } from 'lucide-react';
import { motion, AnimatePresence } from 'framer-motion';

interface BulkFloatingBarProps {
    onAction: (action: 'approve' | 'reject' | 'changes', data?: any) => Promise<void>;
    isProcessing: boolean;
}

export function BulkFloatingBar({ onAction, isProcessing }: BulkFloatingBarProps) {
    const {
        selectedCount,
        clearSelection,
        isAllInQueueSelected
    } = useBulkSelection();

    const [showMore, setShowMore] = useState(false);

    if (selectedCount === 0) return null;

    return (
        <AnimatePresence>
            <motion.div
                initial={{ y: 100, opacity: 0 }}
                animate={{ y: 0, opacity: 1 }}
                exit={{ y: 100, opacity: 0 }}
                className="fixed bottom-6 left-1/2 -translate-x-1/2 z-50 w-full max-w-2xl px-4"
            >
                <div className="bg-slate-900 text-white rounded-2xl shadow-2xl border border-slate-800 p-3 flex items-center justify-between gap-4">
                    {/* Selection Info */}
                    <div className="flex items-center gap-3 pl-2">
                        <div className="w-10 h-10 bg-blue-600 rounded-xl flex items-center justify-center">
                            <Layers className="w-5 h-5" />
                        </div>
                        <div>
                            <p className="text-sm font-bold">
                                {selectedCount} Jobs Selected
                            </p>
                            <p className="text-[10px] text-slate-400 uppercase tracking-wider font-semibold">
                                {isAllInQueueSelected ? 'Entire Queue' : 'Manual Selection'}
                            </p>
                        </div>
                    </div>

                    {/* Primary Actions */}
                    <div className="flex items-center gap-2">
                        <button
                            onClick={() => onAction('approve')}
                            disabled={isProcessing}
                            className="flex items-center gap-2 px-4 py-2.5 bg-green-600 hover:bg-green-500 text-white rounded-xl text-sm font-bold transition-all active:scale-95 disabled:opacity-50"
                        >
                            <ShieldCheck className="w-4 h-4" />
                            Approve
                        </button>

                        <button
                            onClick={() => onAction('changes')}
                            disabled={isProcessing}
                            className="flex items-center gap-2 px-4 py-2.5 bg-slate-700 hover:bg-slate-600 text-white rounded-xl text-sm font-bold transition-all active:scale-95 disabled:opacity-50"
                        >
                            <Edit className="w-4 h-4" />
                            Request Edits
                        </button>

                        <button
                            onClick={() => onAction('reject')}
                            disabled={isProcessing}
                            className="flex items-center gap-2 px-4 py-2.5 bg-red-600 hover:bg-red-500 text-white rounded-xl text-sm font-bold transition-all active:scale-95 disabled:opacity-50"
                        >
                            <AlertTriangle className="w-4 h-4" />
                            Reject
                        </button>

                        <div className="h-8 w-px bg-slate-800 mx-1"></div>

                        <button
                            onClick={clearSelection}
                            disabled={isProcessing}
                            className="p-2.5 hover:bg-slate-800 text-slate-400 hover:text-white rounded-xl transition-colors"
                            title="Clear Selection"
                        >
                            <X className="w-5 h-5" />
                        </button>
                    </div>
                </div>
            </motion.div>
        </AnimatePresence>
    );
}
