// instagram-dock.jsx — floating dock-style nav with Instagram-flavored icons.
// CSS-only animations (floating + hover lift), inline SVG icons, no framer-motion.

const IGIcon = {
  Home: (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" width="22" height="22">
      <path d="M3 11.5 12 4l9 7.5V20a1 1 0 0 1-1 1h-5v-6h-6v6H4a1 1 0 0 1-1-1z" />
    </svg>
  ),
  Search: (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" width="22" height="22">
      <circle cx="11" cy="11" r="7" />
      <path d="m20 20-3.5-3.5" />
    </svg>
  ),
  Reels: (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" width="22" height="22">
      <rect x="3" y="3" width="18" height="18" rx="4" />
      <path d="m17 3-3 5h-3l3-5" />
      <path d="m11 3-3 5H5l3-5" />
      <path d="M3 8h18" />
      <path d="m10 13 5 3-5 3z" fill="currentColor" />
    </svg>
  ),
  Plus: (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" width="22" height="22">
      <rect x="3" y="3" width="18" height="18" rx="5" />
      <path d="M12 8v8M8 12h8" />
    </svg>
  ),
  Heart: (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" width="22" height="22">
      <path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l8.84 8.84 8.84-8.84a5.5 5.5 0 0 0 0-7.78z" />
    </svg>
  ),
  DM: (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" width="22" height="22">
      <path d="m22 2-7 20-4-9-9-4z" />
      <path d="M22 2 11 13" />
    </svg>
  ),
  User: (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" width="22" height="22">
      <circle cx="12" cy="8" r="4" />
      <path d="M4 21v-1a8 8 0 0 1 16 0v1" />
    </svg>
  ),
};

function InstagramDock({ items, accent = '#5b8bff' }) {
  return (
    <div
      className="ig-dock"
      style={{
        display: 'inline-flex',
        gap: 8,
        padding: 12,
        borderRadius: 26,
        background: 'rgba(12,14,18,0.55)',
        backdropFilter: 'blur(16px) saturate(140%)',
        WebkitBackdropFilter: 'blur(16px) saturate(140%)',
        border: '1px solid rgba(244,241,236,0.12)',
        boxShadow:
          '0 12px 48px rgba(0,0,0,0.4),' +
          '0 0 0 1px rgba(255,255,255,0.03) inset,' +
          '0 1px 0 rgba(255,255,255,0.06) inset',
        animation: 'ig-dock-float 6s ease-in-out infinite',
      }}
    >
      {items.map((it, i) => (
        <DockButton key={it.label} item={it} accent={accent} idx={i} />
      ))}
      <style>{`
        @keyframes ig-dock-float {
          0%, 100% { transform: translateY(0); }
          50%      { transform: translateY(-4px); }
        }
        .ig-dock-btn {
          position: relative;
          width: 64px; height: 64px;
          border-radius: 20px;
          display: flex; align-items: center; justify-content: center;
          color: #f4f1ec;
          transition: transform .25s cubic-bezier(.2,.7,.2,1),
                      background .25s, color .25s;
          isolation: isolate;
        }
        .ig-dock-btn svg {
          width: 28px; height: 28px;
        }
        .ig-dock-btn:hover {
          transform: translateY(-6px) scale(1.08);
        }
        .ig-dock-btn::before {
          content: ''; position: absolute; inset: 0;
          border-radius: inherit;
          background: linear-gradient(135deg,
            rgba(91,139,255,0.25), rgba(91,139,255,0));
          opacity: 0; transition: opacity .25s; z-index: -1;
        }
        .ig-dock-btn:hover::before { opacity: 1; }
        .ig-dock-btn.is-add {
          background: linear-gradient(135deg, #5b8bff 0%, #3b6cff 100%);
          color: #f4f1ec;
        }
        .ig-dock-btn.is-add:hover {
          box-shadow: 0 8px 24px rgba(91,139,255,0.5);
        }
        .ig-dock-tip {
          position: absolute;
          top: calc(100% + 12px);
          left: 50%;
          transform: translate(-50%, -4px);
          padding: 7px 12px;
          background: #f4f1ec;
          color: #0c0e12;
          font-size: 12px;
          font-weight: 600;
          letter-spacing: 0.04em;
          text-transform: uppercase;
          border-radius: 8px;
          white-space: nowrap;
          opacity: 0;
          pointer-events: none;
          transition: opacity .2s, transform .2s;
        }
        .ig-dock-tip::after {
          content: '';
          position: absolute;
          bottom: 100%; left: 50%;
          transform: translateX(-50%);
          border: 5px solid transparent;
          border-bottom-color: #f4f1ec;
        }
        .ig-dock-btn:hover .ig-dock-tip {
          opacity: 1;
          transform: translate(-50%, 0);
        }
        .ig-dock-active-dot {
          position: absolute;
          bottom: 8px; left: 50%;
          transform: translateX(-50%);
          width: 5px; height: 5px;
          border-radius: 50%;
          background: ${accent};
          box-shadow: 0 0 8px ${accent};
        }
      `}</style>
    </div>
  );
}

function DockButton({ item, accent, idx }) {
  const Icon = IGIcon[item.icon] || IGIcon.Home;
  const isAdd = item.variant === 'add';
  return (
    <button
      className={`ig-dock-btn ${isAdd ? 'is-add' : ''}`}
      onClick={item.onClick}
      data-cursor-hover
      aria-label={item.label}
    >
      {Icon}
      {item.active ? <span className="ig-dock-active-dot" /> : null}
      <span className="ig-dock-tip">{item.label}</span>
    </button>
  );
}

window.InstagramDock = InstagramDock;
window.IGIcon = IGIcon;
