"use client";

import { useState } from "react";
import { WidgetContainer } from "./WidgetContainer";
import {
    CheckCircle, Search, MapPin,
    TrendingUp, Award, BookOpen, Star, Sparkles, X, ChevronRight, ChevronLeft, FileText
} from "lucide-react";
import Link from "next/link";
import { motion, AnimatePresence } from "framer-motion";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Progress } from "@/components/ui/progress";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";

export function ProfileCompletionWidget({ completion = 75 }) {
    return (
        <WidgetContainer title="Profile Status" icon={<CheckCircle className="text-emerald-500" />}>
            <div className="flex flex-col items-center justify-center text-center">
                <div className="relative w-32 h-32 mb-4">
                    <svg className="w-full h-full transform -rotate-90">
                        <circle cx="64" cy="64" r="56" className="text-slate-100" strokeWidth="12" fill="none" stroke="currentColor" />
                        <circle
                            cx="64" cy="64" r="56"
                            className={`transition-all duration-1000 ease-out ${completion < 50 ? 'text-rose-500' : completion < 80 ? 'text-amber-500' : 'text-emerald-500'}`}
                            strokeWidth="12"
                            fill="none"
                            stroke="currentColor"
                            strokeDasharray={`${2 * Math.PI * 56}`}
                            strokeDashoffset={`${2 * Math.PI * 56 * (1 - completion / 100)}`}
                        />
                    </svg>
                    <div className="absolute inset-0 flex items-center justify-center font-black text-3xl text-slate-800">
                        {completion}%
                    </div>
                </div>
                <p className="font-bold text-slate-900 mb-2">
                    {completion >= 90 ? "Your profile is looking great!" : `Almost there! Your profile is ${completion}% complete.`}
                </p>
                <p className="text-sm text-slate-500 mb-6 px-4">Complete your profile to increase visibility by up to 40% and get better job matches!</p>

                <div className="w-full space-y-2">
                    <div className="flex justify-between items-center p-3 rounded-lg bg-slate-50 border border-slate-100 hover:border-primary/30 transition-colors">
                        <span className="text-sm font-semibold text-slate-700 flex items-center gap-2">
                            <span className="w-1.5 h-1.5 rounded-full bg-rose-500" /> Add work experience
                        </span>
                        <Link href="/dashboard/profile/edit" className="text-xs font-bold text-primary bg-primary/10 px-2 py-1 rounded">2 min</Link>
                    </div>
                    <div className="flex justify-between items-center p-3 rounded-lg bg-slate-50 border border-slate-100 hover:border-primary/30 transition-colors">
                        <span className="text-sm font-semibold text-slate-700 flex items-center gap-2">
                            <span className="w-1.5 h-1.5 rounded-full bg-amber-500" /> Upload your resume
                        </span>
                        <button className="text-xs font-bold text-slate-700 bg-white border border-slate-200 px-2 py-1 rounded shadow-sm hover:bg-slate-50">Upload</button>
                    </div>
                </div>
            </div>
        </WidgetContainer>
    );
}

export function JobSearchWidget() {
    return (
        <WidgetContainer title="Quick Job Search" icon={<Search className="text-indigo-500" />}>
            <form action="/jobs" className="space-y-4">
                <div className="relative">
                    <Search className="absolute left-3 top-1/2 -translate-y-1/2 h-5 w-5 text-slate-400" />
                    <input
                        type="text"
                        name="q"
                        placeholder="Search jobs by title, skill, or company..."
                        className="w-full pl-10 pr-4 py-3 rounded-xl border border-slate-200 focus:border-primary focus:ring-1 focus:ring-primary/20 outline-none transition-all"
                    />
                </div>

                <div className="flex gap-2 text-sm overflow-x-auto pb-2 scrollbar-hide">
                    <button type="button" className="shrink-0 px-3 py-1.5 rounded-lg border border-slate-200 bg-white text-slate-600 font-medium hover:bg-slate-50">Remote</button>
                    <button type="button" className="shrink-0 px-3 py-1.5 rounded-lg border border-slate-200 bg-white text-slate-600 font-medium flex items-center gap-1 hover:bg-slate-50"><MapPin className="h-3 w-3" /> Near me</button>
                    <button type="button" className="shrink-0 px-3 py-1.5 rounded-lg border border-slate-200 bg-white text-slate-600 font-medium hover:bg-slate-50">Full-time</button>
                </div>

                <div className="flex justify-end items-center mt-2">
                    <Button type="submit" size="sm">Search</Button>
                </div>
            </form>
        </WidgetContainer>
    );
}

export function CareerInsightsWidget() {
    return (
        <WidgetContainer title="Career Insights" icon={<Sparkles className="text-amber-500" />}>
            <div className="flex flex-col items-center justify-center py-6 text-center">
                <Sparkles className="h-10 w-10 text-slate-300 mb-3" />
                <p className="font-semibold text-slate-700 mb-1">Personalized Insights</p>
                <p className="text-sm text-slate-500 mb-4">AI-powered career insights based on your profile, skills, and market trends will be available soon.</p>
                <Badge variant="secondary">Coming Soon</Badge>
            </div>
        </WidgetContainer>
    );
}

export function ProfileViewsWidget() {
    return (
        <WidgetContainer title="Profile Views" icon={<TrendingUp className="text-blue-500" />}>
            <div className="flex flex-col items-center justify-center py-6 text-center">
                <TrendingUp className="h-10 w-10 text-slate-300 mb-3" />
                <p className="font-semibold text-slate-700 mb-1">Profile Analytics</p>
                <p className="text-sm text-slate-500 mb-4">See who viewed your profile and track your visibility over time.</p>
                <Badge variant="secondary">Coming Soon</Badge>
            </div>
        </WidgetContainer>
    );
}

export function LearningResourcesWidget() {
    return (
        <WidgetContainer title="Recommended Learning" icon={<BookOpen className="text-rose-500" />}>
            <div className="flex flex-col items-center justify-center py-6 text-center">
                <BookOpen className="h-10 w-10 text-slate-300 mb-3" />
                <p className="font-semibold text-slate-700 mb-1">Learning Hub</p>
                <p className="text-sm text-slate-500 mb-4">Curated courses and articles tailored to your career goals.</p>
                <Badge variant="secondary">Coming Soon</Badge>
            </div>
        </WidgetContainer>
    );
}

export function SkillsAssessmentWidget() {
    return (
        <WidgetContainer title="Skill Badges" icon={<Star className="text-amber-400" />}>
            <div className="flex flex-col items-center justify-center py-6 text-center">
                <Star className="h-10 w-10 text-slate-300 mb-3" />
                <p className="font-semibold text-slate-700 mb-1">Skill Verification</p>
                <p className="text-sm text-slate-500 mb-4">Take skill assessments to earn verified badges and stand out to employers.</p>
                <Badge variant="secondary">Coming Soon</Badge>
            </div>
        </WidgetContainer>
    );
}
