'use client';

import { useState } from 'react';
import { useParams, useRouter } from 'next/navigation';
import { motion, AnimatePresence } from 'framer-motion';
import {
  ArrowLeft,
  Edit2,
  Trash2,
  Package,
  TrendingUp,
  ShoppingCart,
  AlertTriangle,
  ChevronLeft,
  ChevronRight,
  Loader2,
  Copy,
  Check,
  BarChart3,
  Tag,
  Layers,
  ExternalLink,
  Sparkles,
  ChevronDown,
} from 'lucide-react';
import { cn, formatIDR } from '@/lib/utils';
import { useAdminProductBySlug, useDeleteProduct } from '@/hooks';
import type { Product, ProductVariant } from '@/lib/services/product.service';
import { useUpdateProductStatus } from '@/hooks/useProducts';

import Image from 'next/image';
// ── Copy button ────────────────────────────────────────────────────────
function CopyButton({ text }: { text: string }) {
  const [copied, setCopied] = useState(false);
  const copy = () => {
    navigator.clipboard.writeText(text);
    setCopied(true);
    setTimeout(() => setCopied(false), 1500);
  };
  return (
    <button
      onClick={copy}
      className={cn(
        'flex items-center gap-1.5 px-3 py-1.5 rounded-lg border text-[10px] font-bold uppercase tracking-widest transition-all',
        copied
          ? 'bg-emerald-50 border-emerald-200 text-emerald-600'
          : 'bg-gray-50 border-gray-200 text-gray-500 hover:text-gray-900 hover:bg-white'
      )}
    >
      {copied ? <Check className="w-3 h-3" /> : <Copy className="w-3 h-3" />}
      {copied ? 'Disalin' : 'Salin'}
    </button>
  );
}

// ── Glass card ─────────────────────────────────────────────────────────
function GlassCard({
  children,
  className,
  delay = 0,
}: {
  children: React.ReactNode;
  className?: string;
  delay?: number;
}) {
  return (
    <motion.div
      initial={{ opacity: 0, y: 12 }}
      animate={{ opacity: 1, y: 0 }}
      transition={{ delay, duration: 0.45, ease: [0.22, 1, 0.36, 1] }}
      className={cn(
        'relative bg-white/60 backdrop-blur-xl border border-gray-200 rounded-3xl overflow-hidden shadow-sm',
        className
      )}
    >
      {children}
    </motion.div>
  );
}

// ── Section header ─────────────────────────────────────────────────────
function SectionHeader({
  icon: Icon,
  label,
  action,
}: {
  icon: React.ElementType;
  label: string;
  action?: React.ReactNode;
}) {
  return (
    <div className="flex items-center justify-between px-6 sm:px-8 py-5 border-b border-gray-200 bg-white/40">
      <div className="flex items-center gap-3">
        <div className="p-2 bg-yellow-50 border border-yellow-200 rounded-xl shadow-sm">
          <Icon className="w-4 h-4 text-yellow-600" />
        </div>
        <span className="text-sm font-bold text-gray-900 tracking-wide">
          {label}
        </span>
      </div>
      {action}
    </div>
  );
}

// ── Stat card ──────────────────────────────────────────────────────────
function StatCard({
  icon: Icon,
  label,
  value,
  sub,
  iconColor,
  glowColor,
}: {
  icon: React.ElementType;
  label: string;
  value: string | number;
  sub?: string;
  iconColor: string;
  glowColor: string;
}) {
  return (
    <div className="relative border border-gray-200 bg-white/60 backdrop-blur-md rounded-2xl px-5 py-5 overflow-hidden shadow-sm">
      <div
        className="absolute -top-6 -right-6 w-24 h-24 rounded-full blur-3xl pointer-events-none"
        style={{ background: glowColor }}
      />
      <div
        className={cn(
          'w-10 h-10 rounded-xl flex items-center justify-center mb-3 bg-white border border-gray-100 shadow-sm',
          iconColor
        )}
      >
        <Icon className="w-4 h-4" />
      </div>
      <p className="text-[10px] font-bold text-gray-500 uppercase tracking-widest mb-1">
        {label}
      </p>
      <p className="text-xl font-black text-gray-900 tracking-tight">{value}</p>
      {sub && (
        <p className="text-[10px] font-medium text-gray-500 mt-1">{sub}</p>
      )}
    </div>
  );
}

// ── Info row ───────────────────────────────────────────────────────────
function InfoRow({
  label,
  children,
}: {
  label: string;
  children: React.ReactNode;
}) {
  return (
    <div className="flex items-center justify-between gap-4 py-3.5 border-b border-gray-100 last:border-0">
      <span className="text-xs font-bold text-gray-600 tracking-wide shrink-0">
        {label}
      </span>
      <div className="text-right">{children}</div>
    </div>
  );
}

// ── Status badge ───────────────────────────────────────────────────────
function Badge({
  children,
  variant = 'default',
}: {
  children: React.ReactNode;
  variant?: 'green' | 'red' | 'amber' | 'yellow' | 'default';
}) {
  return (
    <span
      className={cn(
        'inline-flex items-center gap-1.5 text-[10px] font-bold px-3 py-1.5 rounded-full uppercase tracking-widest border',
        variant === 'green' &&
          'bg-emerald-50 text-emerald-700 border-emerald-200',
        variant === 'red' && 'bg-rose-50 text-rose-700 border-rose-200',
        variant === 'amber' && 'bg-amber-50 text-amber-700 border-amber-200',
        variant === 'yellow' &&
          'bg-yellow-50 text-yellow-700 border-yellow-200',
        variant === 'default' && 'bg-gray-50 text-gray-700 border-gray-200'
      )}
    >
      {children}
    </span>
  );
}

// ── Image gallery ──────────────────────────────────────────────────────
function ImageGallery({ product }: { product: Product }) {
  const [active, setActive] = useState(0);
  const images: string[] = product.primary_image_url
    ? [product.primary_image_url]
    : [];

  if (images.length === 0) {
    return (
      <div className="aspect-square rounded-3xl border border-gray-200 bg-white/60 backdrop-blur-xl flex flex-col items-center justify-center shadow-sm">
        <Package className="w-16 h-16 text-gray-400 mb-4" />
        <span className="text-sm font-medium text-gray-500">
          Tidak ada gambar
        </span>
      </div>
    );
  }

  return (
    <div className="space-y-4">
      {/* Main image */}
      <div className="relative aspect-square rounded-3xl border border-gray-200 bg-white overflow-hidden group shadow-sm">
        {}
        <Image
          src={images[active]}
          alt={product.name}
          className="w-full h-full object-cover transition-all duration-700 hover:scale-105"
          width={500}
          height={500}
        />
        {images.length > 1 && (
          <>
            <button
              onClick={() =>
                setActive((a) => (a - 1 + images.length) % images.length)
              }
              className="absolute left-4 top-1/2 -translate-y-1/2 w-10 h-10 rounded-full border border-gray-200 bg-white/90 backdrop-blur-md flex items-center justify-center text-gray-700 hover:bg-yellow-400 hover:text-yellow-900 hover:border-yellow-400 shadow-sm transition-all opacity-0 group-hover:opacity-100"
            >
              <ChevronLeft className="w-5 h-5" />
            </button>
            <button
              onClick={() => setActive((a) => (a + 1) % images.length)}
              className="absolute right-4 top-1/2 -translate-y-1/2 w-10 h-10 rounded-full border border-gray-200 bg-white/90 backdrop-blur-md flex items-center justify-center text-gray-700 hover:bg-yellow-400 hover:text-yellow-900 hover:border-yellow-400 shadow-sm transition-all opacity-0 group-hover:opacity-100"
            >
              <ChevronRight className="w-5 h-5" />
            </button>
          </>
        )}
        {/* Image count pill */}
        {images.length > 1 && (
          <div className="absolute bottom-4 right-4 bg-white/90 backdrop-blur-md border border-gray-200 shadow-sm px-3 py-1.5 rounded-full">
            <span className="text-[10px] font-bold text-gray-700 uppercase tracking-widest">
              {active + 1} / {images.length}
            </span>
          </div>
        )}
      </div>

      {/* Thumbnails */}
      {images.length > 1 && (
        <div className="flex gap-3 overflow-x-auto pb-2 no-scrollbar">
          {images.map((img, i) => (
            <button
              key={i}
              onClick={() => setActive(i)}
              className={cn(
                'w-16 h-16 rounded-xl shrink-0 overflow-hidden transition-all',
                active === i
                  ? 'border-2 border-yellow-400 shadow-[0_0_15px_rgba(250,204,21,0.3)]'
                  : 'border border-gray-200 hover:border-gray-400 opacity-60 hover:opacity-100'
              )}
            >
              {}
              <Image
                src={img}
                alt=""
                className="w-full h-full object-cover"
                width={500}
                height={500}
              />
            </button>
          ))}
        </div>
      )}
    </div>
  );
}

// ── Variant table ──────────────────────────────────────────────────────
function VariantTable({ variants }: { variants: ProductVariant[] }) {
  return (
    <div className="overflow-x-auto p-2">
      <table className="w-full text-sm">
        <thead>
          <tr className="border-b border-gray-200 bg-gray-50/50">
            {[
              'Varian',
              'SKU',
              'Harga',
              'Harga Dist.',
              'Stok',
              'Berat',
              'Status',
            ].map((h) => (
              <th
                key={h}
                className="text-left px-6 py-4 text-[10px] font-bold text-gray-500 uppercase tracking-widest whitespace-nowrap"
              >
                {h}
              </th>
            ))}
          </tr>
        </thead>
        <tbody className="divide-y divide-gray-100">
          {variants.map((v) => (
            <tr key={v.id} className="hover:bg-gray-50/50 transition-colors">
              <td className="px-6 py-4 font-bold text-gray-900 tracking-wide whitespace-nowrap">
                {v.name}
              </td>
              <td className="px-6 py-4">
                <div className="flex items-center gap-2">
                  <span className="font-mono text-xs text-gray-500 bg-gray-100 px-2 py-1 rounded-md border border-gray-200">
                    {v.sku}
                  </span>
                  <CopyButton text={v.sku} />
                </div>
              </td>
              <td className="px-6 py-4 font-black text-yellow-600 whitespace-nowrap">
                {formatIDR(Number(v.price))}
              </td>
              <td className="px-6 py-4 font-black text-emerald-600 whitespace-nowrap">
                {v.price_distributor
                  ? formatIDR(Number(v.price_distributor))
                  : '-'}
              </td>
              <td className="px-6 py-4">
                <span
                  className={cn(
                    'font-black tabular-nums',
                    v.is_out_of_stock
                      ? 'text-rose-500'
                      : v.is_low_stock
                        ? 'text-amber-500'
                        : 'text-gray-900'
                  )}
                >
                  {v.stock.toLocaleString('id-ID')}
                </span>
              </td>
              <td className="px-6 py-4 text-gray-500 font-medium whitespace-nowrap">
                {v.weight}g
              </td>
              <td className="px-6 py-4">
                {v.is_out_of_stock ? (
                  <Badge variant="red">Habis</Badge>
                ) : v.is_low_stock ? (
                  <Badge variant="amber">Terbatas</Badge>
                ) : (
                  <Badge variant="green">Tersedia</Badge>
                )}
              </td>
            </tr>
          ))}
        </tbody>
      </table>
    </div>
  );
}

// ── Delete dialog ──────────────────────────────────────────────────────
function DeleteDialog({
  product,
  onConfirm,
  onCancel,
  isLoading,
}: {
  product: Product;
  onConfirm: () => void;
  onCancel: () => void;
  isLoading: boolean;
}) {
  return (
    <div className="fixed inset-0 z-50 flex items-center justify-center p-4">
      <motion.div
        initial={{ opacity: 0 }}
        animate={{ opacity: 1 }}
        exit={{ opacity: 0 }}
        className="absolute inset-0 bg-black/60 backdrop-blur-sm"
        onClick={onCancel}
      />
      <motion.div
        initial={{ opacity: 0, scale: 0.95, y: 10 }}
        animate={{ opacity: 1, scale: 1, y: 0 }}
        exit={{ opacity: 0, scale: 0.95, y: 10 }}
        className="relative bg-white border border-gray-200 rounded-3xl p-6 w-full max-w-sm overflow-hidden shadow-2xl"
      >
        <div className="absolute top-0 left-1/2 -translate-x-1/2 w-32 h-32 bg-rose-500/20 blur-3xl pointer-events-none rounded-full" />
        <div className="flex items-center gap-4 mb-6 relative z-10">
          <div className="w-12 h-12 rounded-full border border-rose-200 bg-rose-50 flex items-center justify-center shrink-0">
            <AlertTriangle className="w-6 h-6 text-rose-500" />
          </div>
          <div>
            <h3 className="text-lg font-black text-gray-900 tracking-wide">
              Hapus Produk?
            </h3>
            <p className="text-[10px] text-gray-500 font-bold uppercase tracking-widest mt-0.5">
              Tindakan permanen
            </p>
          </div>
        </div>
        <p className="text-sm font-medium text-gray-600 mb-8 leading-relaxed relative z-10">
          Produk{' '}
          <span className="font-bold text-gray-900 px-1">{product.name}</span>{' '}
          beserta semua varian dan gambar akan dihapus dari sistem.
        </p>
        <div className="flex gap-3 relative z-10">
          <button
            onClick={onCancel}
            className="flex-1 py-3 px-4 rounded-xl text-xs font-bold text-gray-600 bg-white border border-gray-200 hover:bg-gray-50 hover:text-gray-900 uppercase tracking-wider transition-all shadow-sm"
          >
            Batal
          </button>
          <button
            onClick={onConfirm}
            disabled={isLoading}
            className="flex-1 py-3 px-4 rounded-xl text-xs font-bold text-white bg-rose-500 hover:bg-rose-600 uppercase tracking-wider transition-all flex items-center justify-center gap-2 disabled:opacity-50 shadow-sm"
          >
            {isLoading ? (
              <Loader2 className="w-4 h-4 animate-spin" />
            ) : (
              <Trash2 className="w-4 h-4" />
            )}{' '}
            Hapus
          </button>
        </div>
      </motion.div>
    </div>
  );
}

// ── Page ───────────────────────────────────────────────────────────────
export default function AdminProductDetailPage() {
  const router = useRouter();
  const params = useParams();
  const slug = params.slug as string;

  const { data: product, isLoading } = useAdminProductBySlug(slug);
  const deleteMutation = useDeleteProduct();
  const updateStatusMutation = useUpdateProductStatus();
  const [showDelete, setShowDelete] = useState(false);

  const handleDelete = () => {
    if (!product) return;
    deleteMutation.mutate(product.id, {
      onSuccess: () => router.push('/dashboard/admin/products'),
    });
  };

  if (isLoading) {
    return (
      <div className="max-w-6xl mx-auto space-y-6 pt-4 relative z-10">
        <div className="grid lg:grid-cols-[380px_1fr] gap-6">
          <div className="space-y-6">
            <div className="aspect-square rounded-3xl bg-white border border-gray-200 animate-pulse shadow-sm" />
            <div className="h-64 rounded-3xl bg-white border border-gray-200 animate-pulse shadow-sm" />
          </div>
          <div className="space-y-6">
            <div className="grid grid-cols-2 sm:grid-cols-4 gap-4">
              {Array.from({ length: 4 }).map((_, i) => (
                <div
                  key={i}
                  className="h-28 rounded-2xl bg-white border border-gray-200 animate-pulse shadow-sm"
                />
              ))}
            </div>
            <div className="h-48 rounded-3xl bg-white border border-gray-200 animate-pulse shadow-sm" />
            <div className="h-32 rounded-3xl bg-white border border-gray-200 animate-pulse shadow-sm" />
          </div>
        </div>
      </div>
    );
  }

  if (!product) {
    return (
      <div className="flex flex-col items-center justify-center py-32 text-center relative z-10">
        <div className="w-20 h-20 bg-white border border-gray-200 rounded-full flex items-center justify-center mb-6 shadow-sm">
          <Package className="w-10 h-10 text-gray-400" />
        </div>
        <h2 className="font-black text-gray-900 text-2xl tracking-tight mb-2">
          Produk Tidak Ditemukan
        </h2>
        <p className="text-gray-500 text-sm mb-6">
          Mungkin URL salah atau produk telah dihapus.
        </p>
        <button
          onClick={() => router.back()}
          className="inline-flex items-center gap-2 px-6 py-3 rounded-xl bg-yellow-400 text-yellow-900 font-bold text-sm transition-all hover:bg-yellow-500 shadow-lg shadow-yellow-400/20"
        >
          <ArrowLeft className="w-4 h-4" /> Kembali
        </button>
      </div>
    );
  }

  const isOutOfStock = product.variants.every((v) => v.is_out_of_stock);
  const priceLabel =
    product.min_price === product.max_price
      ? formatIDR(product.min_price)
      : `${formatIDR(product.min_price)} – ${formatIDR(product.max_price)}`;

  return (
    <div className="min-h-screen bg-transparent text-gray-900 relative overflow-hidden pb-24">
      {/* Background Glow Blobs */}
      <div className="absolute top-0 right-0 w-[500px] h-[500px] bg-yellow-400/10 rounded-full blur-[120px] pointer-events-none z-0" />
      <div className="absolute bottom-1/4 left-0 w-[400px] h-[400px] bg-yellow-400/10 rounded-full blur-[120px] pointer-events-none z-0" />

      <div className="relative z-10 max-w-6xl mx-auto space-y-6 pt-4">
        {/* ── Header ── */}
        <motion.div
          initial={{ opacity: 0, y: 12 }}
          animate={{ opacity: 1, y: 0 }}
          className="flex flex-col sm:flex-row sm:items-end justify-between gap-6"
        >
          <div className="flex items-start gap-4">
            <button
              onClick={() => router.push('/dashboard/admin/products')}
              className="p-3 rounded-xl bg-white/60 backdrop-blur-md border border-gray-200 text-gray-500 hover:text-gray-900 hover:bg-white shadow-sm transition-all mt-1 shrink-0"
            >
              <ArrowLeft className="w-5 h-5" />
            </button>
            <div>
              <h2 className="text-3xl font-black text-gray-900 tracking-tight leading-none mb-3">
                {product.name}
              </h2>
              <div className="flex items-center gap-3 flex-wrap">
                <span className="text-[10px] font-mono font-bold text-gray-500 uppercase tracking-widest bg-gray-100 border border-gray-200 px-2.5 py-1 rounded-md">
                  SKU: {product.sku}
                </span>
                <CopyButton text={product.sku} />
              </div>
            </div>
          </div>

          <div className="flex items-center gap-3 shrink-0">
            <a
              href={`/products/${product.slug}`}
              target="_blank"
              rel="noopener noreferrer"
              className="hidden sm:flex items-center gap-2 px-5 py-3 rounded-xl border border-gray-200 bg-white/60 text-gray-600 hover:text-gray-900 hover:bg-white text-xs font-bold uppercase tracking-wider transition-all shadow-sm"
            >
              <ExternalLink className="w-4 h-4" /> Lihat di Toko
            </a>
            <button
              onClick={() =>
                router.push(`/dashboard/admin/products/${product.slug}/edit`)
              }
              className="flex items-center gap-2 px-6 py-3 rounded-xl bg-yellow-400 hover:bg-yellow-500 text-yellow-900 text-xs font-bold uppercase tracking-wider transition-all shadow-lg shadow-yellow-400/20"
            >
              <Edit2 className="w-4 h-4" /> Edit
            </button>
          </div>
        </motion.div>

        {/* ── Main grid ── */}
        <div className="grid lg:grid-cols-[380px_1fr] gap-6 items-start">
          {/* ── LEFT ── */}
          <div className="space-y-6">
            <motion.div
              initial={{ opacity: 0, y: 12 }}
              animate={{ opacity: 1, y: 0 }}
              transition={{ delay: 0.05 }}
            >
              <ImageGallery product={product} />
            </motion.div>

            <GlassCard delay={0.08}>
              <SectionHeader icon={Tag} label="Informasi Produk" />
              <div className="px-6 sm:px-8 py-2">
                {/* ── SELECT STATUS INTERAKTIF ── */}
                <InfoRow label="Status">
                  <div className="flex items-center gap-2 justify-end">
                    {updateStatusMutation.isPending && (
                      <Loader2 className="w-4 h-4 animate-spin text-[#FFD738]" />
                    )}
                    <div className="relative inline-block">
                      <select
                        value={product.status}
                        onChange={(e) =>
                          updateStatusMutation.mutate({
                            id: product.id,
                            status: e.target.value,
                          })
                        }
                        disabled={updateStatusMutation.isPending}
                        className={cn(
                          'appearance-none text-[10px] font-bold py-1.5 pl-3 pr-8 rounded-full uppercase tracking-widest border transition-all cursor-pointer outline-none focus:ring-1 focus:ring-yellow-400',
                          product.status === 'active' &&
                            'bg-emerald-50 text-emerald-700 border-emerald-200',
                          product.status === 'inactive' &&
                            'bg-rose-50 text-rose-700 border-rose-200',
                          product.status === 'draft' &&
                            'bg-amber-50 text-amber-700 border-amber-200',
                          'disabled:opacity-50 disabled:cursor-not-allowed'
                        )}
                      >
                        <option
                          value="active"
                          className="bg-white text-emerald-700 font-bold"
                        >
                          AKTIF
                        </option>
                        <option
                          value="inactive"
                          className="bg-white text-rose-700 font-bold"
                        >
                          NONAKTIF
                        </option>
                        <option
                          value="draft"
                          className="bg-white text-amber-700 font-bold"
                        >
                          DRAFT
                        </option>
                      </select>
                      <ChevronDown
                        className={cn(
                          'absolute right-2.5 top-1/2 -translate-y-1/2 w-3 h-3 pointer-events-none opacity-70',
                          product.status === 'active' && 'text-emerald-700',
                          product.status === 'inactive' && 'text-rose-700',
                          product.status === 'draft' && 'text-amber-700'
                        )}
                      />
                    </div>
                  </div>
                </InfoRow>

                <InfoRow label="Stok">
                  {isOutOfStock ? (
                    <Badge variant="red">Habis</Badge>
                  ) : (
                    <Badge variant="green">Tersedia</Badge>
                  )}
                </InfoRow>
                <InfoRow label="Unggulan">
                  {product.is_featured ? (
                    <Badge variant="yellow">
                      <Sparkles className="w-3 h-3" /> Unggulan
                    </Badge>
                  ) : (
                    <span className="text-xs text-gray-500 font-bold">—</span>
                  )}
                </InfoRow>
                <InfoRow label="Kategori">
                  <Badge variant="default">{product.category.name}</Badge>
                </InfoRow>
                <InfoRow label="Harga">
                  <span className="font-black text-yellow-600 text-base">
                    {priceLabel}
                  </span>
                </InfoRow>
                <InfoRow label="Dibuat Pada">
                  <span className="text-xs font-medium text-gray-500">
                    {new Date(product.created_at).toLocaleDateString('id-ID', {
                      day: 'numeric',
                      month: 'long',
                      year: 'numeric',
                    })}
                  </span>
                </InfoRow>
              </div>
            </GlassCard>

            <GlassCard delay={0.12}>
              <SectionHeader icon={Tag} label="Kategori" />
              <div className="flex items-center gap-4 px-6 sm:px-8 py-6">
                {product.category.image_url ? (
                  <Image
                    src={product.category.image_url}
                    alt={product.category.name}
                    className="w-14 h-14 object-cover rounded-xl border border-gray-200 shrink-0 shadow-sm"
                    width={500}
                    height={500}
                  />
                ) : (
                  <div className="w-14 h-14 rounded-xl bg-gray-50 border border-gray-200 flex items-center justify-center shrink-0 shadow-sm">
                    <Tag className="w-6 h-6 text-gray-400" />
                  </div>
                )}
                <div>
                  <p className="font-bold text-gray-900 text-base tracking-wide">
                    {product.category.name}
                  </p>
                  <p className="text-[10px] font-mono font-medium text-gray-500 mt-0.5">
                    /{product.category.slug}
                  </p>
                </div>
              </div>
            </GlassCard>
          </div>

          {/* ── RIGHT ── */}
          <div className="space-y-6">
            <div className="grid grid-cols-1 sm:grid-cols-3 gap-4">
              <StatCard
                icon={ShoppingCart}
                label="Terjual"
                value={product.total_sold.toLocaleString('id-ID')}
                sub="total unit"
                iconColor="text-emerald-400"
                glowColor="rgba(52,211,153,0.15)"
              />
              <StatCard
                icon={TrendingUp}
                label="Min Harga"
                value={formatIDR(product.min_price)}
                iconColor="text-blue-400"
                glowColor="rgba(59,130,246,0.15)"
              />
              <StatCard
                icon={BarChart3}
                label="Maks Harga"
                value={formatIDR(product.max_price)}
                iconColor="text-violet-400"
                glowColor="rgba(139,92,246,0.15)"
              />
            </div>

            <GlassCard delay={0.1}>
              <SectionHeader icon={Layers} label="Varian Produk" />
              <VariantTable variants={product.variants} />
            </GlassCard>

            {(product.description || product.short_description) && (
              <GlassCard delay={0.13}>
                <SectionHeader icon={Package} label="Deskripsi Produk" />
                <div className="p-6 sm:p-8 space-y-6">
                  {product.short_description && (
                    <div className="bg-yellow-50/50 border border-yellow-200 p-5 rounded-2xl shadow-sm">
                      <p className="text-sm font-medium text-gray-700 leading-relaxed">
                        {product.short_description}
                      </p>
                    </div>
                  )}
                  {product.description && (
                    <div className="prose prose-sm max-w-none text-gray-600">
                      <p className="leading-relaxed whitespace-pre-line">
                        {product.description}
                      </p>
                    </div>
                  )}
                </div>
              </GlassCard>
            )}
          </div>
        </div>
      </div>

      <AnimatePresence>
        {showDelete && (
          <DeleteDialog
            product={product}
            onConfirm={handleDelete}
            onCancel={() => setShowDelete(false)}
            isLoading={deleteMutation.isPending}
          />
        )}
      </AnimatePresence>
    </div>
  );
}
