import React, { useState } from 'react';
import { Head, Link } from '@inertiajs/react';
import { 
    Home, 
    Search,
    Bell,
    MapPin,
    ChevronRight,
    MessageCircle,
    User,
    Compass,
    SlidersHorizontal,
    Briefcase
} from 'lucide-react';

export default function WorkerExplore() {
    const [showFilters, setShowFilters] = useState(false);
    const categories = ['All', 'Cleaning', 'Driver', 'Mason', 'Electrician', 'Carpenter'];
    const [activeCat, setActiveCat] = useState('All');

    const jobs = [
        { id: 1, title: 'Concrete Mason', company: 'BuildRight Ltd', salary: 'AED 3,500', loc: 'Deira', type: 'Full-time', bg: 'bg-blue-50/50', icon: '🏗️' },
        { id: 2, title: 'Home Sanitizer', company: 'PureClean', salary: 'AED 2,200', loc: 'Marina', type: 'Part-time', bg: 'bg-emerald-50/50', icon: '🧼' },
        { id: 3, title: 'Light Driver', company: 'Zayed Logistics', salary: 'AED 4,000', loc: 'Al Quoz', type: 'Full-time', bg: 'bg-purple-50/50', icon: '🚗' },
        { id: 4, title: 'General Helper', company: 'Global Pack', salary: 'AED 1,800', loc: 'Jebel Ali', type: 'Full-time', bg: 'bg-rose-50/50', icon: '📦' },
    ];

    return (
        <div className="min-h-screen bg-[#F9F9F9] font-sans text-slate-900 flex flex-col max-w-md mx-auto shadow-2xl relative overflow-hidden pb-24">
            <Head title="Jobs" />
            
            {/* Header / Search Area */}
            <div className="px-6 pt-12 pb-6 bg-white space-y-6 sticky top-0 z-50 border-b border-slate-50">
                <div className="flex items-center justify-between">
                    <h1 className="text-xl font-black uppercase tracking-tight">Jobs</h1>
                    <button 
                        onClick={() => setShowFilters(true)}
                        className="w-10 h-10 rounded-full bg-slate-50 flex items-center justify-center text-slate-900 border border-slate-100 active:scale-95 transition-all"
                    >
                        <SlidersHorizontal className="w-5 h-5" />
                    </button>
                </div>

                {/* Search Bar */}
                <div className="relative">
                    <Search className="absolute left-4 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-300" />
                    <input 
                        type="text" 
                        placeholder="Search jobs, companies..." 
                        className="w-full pl-12 pr-6 py-4 bg-slate-50 border-none rounded-2xl text-[11px] font-black uppercase tracking-tight shadow-sm focus:ring-4 focus:ring-blue-100 outline-none transition-all"
                    />
                </div>

                {/* Category Chips */}
                <div className="flex space-x-3 overflow-x-auto pb-1 no-scrollbar">
                    {categories.map((cat) => (
                        <button 
                            key={cat} 
                            onClick={() => setActiveCat(cat)}
                            className={`shrink-0 px-5 py-3 rounded-2xl font-black text-[10px] uppercase tracking-widest transition-all active:scale-95 ${
                                activeCat === cat 
                                    ? 'bg-[#185FA5] text-white shadow-lg shadow-blue-500/20' 
                                    : 'bg-white text-slate-400 border border-slate-50'
                            }`}
                        >
                            {cat}
                        </button>
                    ))}
                </div>
            </div>

            <div className="flex-1 overflow-y-auto px-6 py-8 space-y-6 no-scrollbar">
                <div className="flex items-center justify-between">
                    <h3 className="font-black text-[10px] uppercase tracking-[0.2em] text-slate-300">Found {jobs.length} Jobs</h3>
                    <div className="flex items-center space-x-2 text-[10px] font-black text-[#185FA5] uppercase">
                        <MapPin className="w-3 h-3" />
                        <span>Dubai, UAE</span>
                    </div>
                </div>

                {/* Job List */}
                <div className="space-y-4 pb-10">
                    {jobs.map((job) => (
                        <Link 
                            key={job.id} 
                            href="/mobile/worker/job/detail"
                            className="bg-white p-6 rounded-[32px] border border-slate-100 shadow-sm space-y-5 active:scale-[0.98] transition-all block"
                        >
                            <div className="flex items-start justify-between">
                                <div className="w-12 h-12 rounded-full bg-slate-50 flex items-center justify-center text-slate-900 border border-slate-100/50">
                                    <div className="text-xl">{job.icon}</div>
                                </div>
                                <div className="text-right">
                                    <span className="text-lg font-black text-[#185FA5]">{job.salary}</span>
                                </div>
                            </div>

                            <div className="space-y-3">
                                <h3 className="font-black text-slate-900 text-[17px] tracking-tight leading-tight">{job.title}</h3>
                                <div className="space-y-1">
                                    <p className="text-sm font-medium text-slate-400 leading-tight">
                                        High street avenue<br />
                                        London, UK
                                    </p>
                                </div>
                                <p className="text-sm font-black text-slate-900">From Fri, 17 Dec</p>
                            </div>

                            <div className="flex items-center">
                                <span className="bg-blue-50/50 text-[#185FA5] px-5 py-2 rounded-full text-xs font-black uppercase tracking-tight">
                                    {job.type}
                                </span>
                            </div>
                        </Link>
                    ))}
                </div>
            </div>

            {/* Filter Bottom Sheet */}
            {showFilters && (
                <div className="fixed inset-0 z-[100] flex items-end justify-center px-4 pb-4">
                    <div className="absolute inset-0 bg-slate-900/60 backdrop-blur-sm" onClick={() => setShowFilters(false)} />
                    
                    <div className="relative w-full max-w-md bg-white rounded-[40px] shadow-2xl animate-in slide-in-from-bottom duration-300 overflow-hidden">
                        {/* Handle */}
                        <div className="w-full flex justify-center py-4">
                            <div className="w-12 h-1.5 bg-slate-100 rounded-full" />
                        </div>

                        <div className="px-8 pb-10 space-y-8">
                            <div className="flex items-center justify-between">
                                <h2 className="text-xl font-black text-slate-900 tracking-tight">Filter result</h2>
                                <span className="text-xs font-bold text-slate-400 uppercase tracking-widest">22 result</span>
                            </div>

                            <div className="space-y-10 max-h-[60vh] overflow-y-auto no-scrollbar py-2">
                                {/* Sort By */}
                                <div className="space-y-4">
                                    <h3 className="text-sm font-black text-slate-900">Sort by</h3>
                                    <div className="flex flex-wrap gap-2.5">
                                        {['Default', 'Latest First', 'Oldest First', 'Price: Low to High', 'Price: High to Low'].map((opt, i) => (
                                            <button key={opt} className={`px-6 py-3 rounded-2xl text-[10px] font-black uppercase tracking-widest transition-all border ${i === 0 ? 'bg-blue-50 border-blue-100 text-[#185FA5]' : 'bg-white border-slate-100 text-slate-400'}`}>
                                                {opt}
                                            </button>
                                        ))}
                                    </div>
                                </div>

                                {/* Contract Type */}
                                <div className="space-y-4">
                                    <h3 className="text-sm font-black text-slate-900">Contract type</h3>
                                    <div className="flex flex-wrap gap-2.5">
                                        {['Part time', 'Full time', 'Contractual'].map((opt) => (
                                            <button key={opt} className="px-6 py-3 rounded-2xl bg-white border border-slate-100 text-slate-400 text-[10px] font-black uppercase tracking-widest transition-all">
                                                {opt}
                                            </button>
                                        ))}
                                    </div>
                                </div>

                                {/* Skill Range */}
                                <div className="space-y-4">
                                    <h3 className="text-sm font-black text-slate-900">Skill range</h3>
                                    <div className="flex flex-wrap gap-2.5">
                                        {['Junior', 'Medium', 'Expert'].map((opt) => (
                                            <button key={opt} className="px-6 py-3 rounded-2xl bg-white border border-slate-100 text-slate-400 text-[10px] font-black uppercase tracking-widest transition-all">
                                                {opt}
                                            </button>
                                        ))}
                                    </div>
                                </div>

                                {/* Salary Type */}
                                <div className="space-y-4">
                                    <h3 className="text-sm font-black text-slate-900">Salary type</h3>
                                    <div className="flex flex-wrap gap-2.5">
                                        {['Hourly Rate', 'Fix Rate'].map((opt) => (
                                            <button key={opt} className="px-6 py-3 rounded-2xl bg-white border border-slate-100 text-slate-400 text-[10px] font-black uppercase tracking-widest transition-all">
                                                {opt}
                                            </button>
                                        ))}
                                    </div>
                                </div>
                            </div>

                            {/* Actions */}
                            <div className="flex items-center space-x-4 pt-4 border-t border-slate-50">
                                <button onClick={() => setShowFilters(false)} className="flex-1 py-5 bg-blue-50 text-[#185FA5] rounded-[24px] font-black text-[11px] uppercase tracking-[0.2em] active:scale-95 transition-all">
                                    Reset
                                </button>
                                <button onClick={() => setShowFilters(false)} className="flex-1 py-5 bg-[#185FA5] text-white rounded-[24px] font-black text-[11px] uppercase tracking-[0.2em] shadow-xl shadow-blue-500/20 active:scale-95 transition-all">
                                    Apply
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            )}

            {/* Bottom Navigation */}
            <div className="fixed bottom-0 left-0 right-0 max-w-md mx-auto bg-white/90 backdrop-blur-xl border-t border-slate-100 px-6 py-4 flex items-center justify-between z-50">
                <Link href="/mobile/worker/home" className="flex flex-col items-center space-y-1 text-slate-300">
                    <Home className="w-5 h-5" />
                    <span className="text-[8px] font-black uppercase tracking-tight">Home</span>
                </Link>
                <Link href="/mobile/worker/explore" className="flex flex-col items-center space-y-1 text-[#185FA5]">
                    <Briefcase className="w-5 h-5 fill-current" />
                    <span className="text-[8px] font-black uppercase tracking-tight">Jobs</span>
                </Link>
                <Link href="/mobile/worker/announcements" className="flex flex-col items-center space-y-1 text-slate-300">
                    <Bell className="w-5 h-5" />
                    <span className="text-[8px] font-black uppercase tracking-tight">Updates</span>
                </Link>
                <Link href="/mobile/worker/chat" className="flex flex-col items-center space-y-1 text-slate-300">
                    <MessageCircle className="w-5 h-5" />
                    <span className="text-[8px] font-black uppercase tracking-tight">Chat</span>
                </Link>
                <Link href="/mobile/worker/profile" className="flex flex-col items-center space-y-1 text-slate-300">
                    <User className="w-5 h-5" />
                    <span className="text-[8px] font-black uppercase tracking-tight">Profile</span>
                </Link>
            </div>
        </div>
    );
}
