"use client";

import React from "react";
import { usePathname } from "next/navigation";
import { getWhatsAppUrl } from "@/config/business";

export default function FloatingWhatsApp() {
  const pathname = usePathname();

  // Do not show public WhatsApp button in admin backoffice
  if (pathname.startsWith("/admin")) {
    return null;
  }

  const defaultMsg = "¡Hola Sanlore Pizza! Me gustaría hacer un pedido a domicilio en Pereira / Galicia 🍕";
  const url = getWhatsAppUrl(defaultMsg);

  return (
    <a
      id="floating-whatsapp-btn"
      href={url}
      target="_blank"
      rel="noopener noreferrer"
      className="fixed bottom-6 right-6 z-40 flex items-center gap-2.5 bg-[#25d366] hover:bg-[#20ba5a] text-white px-4 py-3 rounded-[8px] border border-white/20 transition-all duration-200 font-bold text-xs uppercase tracking-wider"
      aria-label="Pedir pizza por WhatsApp en Pereira Galicia"
    >
      <span className="relative flex h-2.5 w-2.5">
        <span className="animate-ping absolute inline-flex h-full w-full rounded-full bg-[#ffc324] opacity-80"></span>
        <span className="relative inline-flex rounded-full h-2.5 w-2.5 bg-[#ffc324]"></span>
      </span>
      <span>WhatsApp</span>
      <svg
        viewBox="0 0 32 32"
        width="18"
        height="18"
        fill="currentColor"
        xmlns="http://www.w3.org/2000/svg"
        className="ml-0.5"
      >
        <path d="M16.02 2C8.28 2 2 8.28 2 16.02c0 2.66.75 5.23 2.17 7.46L2.3 29.7l6.44-1.83a14.02 14.02 0 007.28 2.05c7.74 0 14.02-6.28 14.02-14.02C30.04 8.28 23.76 2 16.02 2zm8.18 19.83c-.34.97-1.72 1.83-2.77 2.05-.72.15-1.66.27-4.82-1.04-4.04-1.67-6.66-5.77-6.86-6.04-.2-.27-1.65-2.2-1.65-4.19s1.04-2.98 1.41-3.38c.37-.41.81-.51 1.08-.51.27 0 .54 0 .78.01.25.01.59-.1.92.7.34.81 1.15 2.8 1.25 3.01.1.2.17.44.03.71-.13.27-.2.44-.4.67-.2.24-.43.53-.61.71-.2.2-.42.42-.18.83.24.41 1.05 1.73 2.26 2.81 1.55 1.38 2.86 1.81 3.27 2.01.41.2.65.17.89-.1.24-.27 1.02-1.18 1.29-1.59.27-.41.54-.34.92-.2.37.14 2.37 1.12 2.78 1.32.41.2.68.3.78.47.1.17.1 1 . -24 1.97z" />
      </svg>
    </a>
  );
}
