import { Link } from '@inertiajs/react';
import { useCurrentUrl } from '@/hooks/use-current-url';
import type { LucideIcon } from 'lucide-react';

type Step = {
    label: string;
    href: string;
    icon: LucideIcon;
};

export default function SettingsDeliveryStepper({ steps }: { steps: Step[] }) {
    const { isCurrentUrl } = useCurrentUrl();
    const activeIndex = Math.max(
        0,
        steps.findIndex((step) => isCurrentUrl(step.href)),
    );
    const progress =
        steps.length > 1 ? (activeIndex / (steps.length - 1)) * 100 : 0;

    return (
        <div className="relative rounded-2xl border border-blue-100/80 bg-gradient-to-r from-blue-50 via-white to-emerald-50 p-4 shadow-sm backdrop-blur dark:border-blue-900/40 dark:from-blue-950/60 dark:via-neutral-950 dark:to-emerald-950/60">
            <div className="absolute left-4 right-4 top-9 hidden h-0.5 bg-blue-100/70 md:block dark:bg-blue-900/40" />
            <div
                className="absolute left-4 top-9 hidden h-0.5 bg-gradient-to-r from-blue-600 via-emerald-500 to-emerald-400 md:block"
                style={{ width: `${progress}%` }}
            />
            <div className="grid gap-4 md:grid-cols-3">
                {steps.map((step, index) => {
                    const isActive = index === activeIndex;

                    return (
                        <Link
                            key={step.label}
                            href={step.href}
                            className="flex items-center gap-3 rounded-xl px-2 py-1 transition-colors md:flex-col md:gap-2"
                        >
                            <div
                                className={`flex h-10 w-10 items-center justify-center rounded-full border ${
                                    isActive
                                        ? 'border-blue-600 bg-gradient-to-br from-blue-600 to-emerald-500 text-white shadow-md'
                                        : 'border-blue-100 bg-white/80 text-blue-500 dark:border-blue-900/50 dark:bg-neutral-950/40 dark:text-blue-300'
                                }`}
                            >
                                <step.icon className="h-4 w-4" />
                            </div>
                            <span
                                className={`text-sm ${
                                    isActive
                                        ? 'font-semibold text-blue-700 dark:text-blue-200'
                                        : 'text-muted-foreground'
                                }`}
                            >
                                {step.label}
                            </span>
                        </Link>
                    );
                })}
            </div>
        </div>
    );
}
