"use client";

import { useEffect, useState } from "react";
import { Info } from "lucide-react";

import { Button } from "@/components/ui/button";
import {
  WHATSAPP_STORE_NAME,
  buildWhatsAppApiHref,
} from "@/components/shop/whatsapp-shared";

export default function HomeHeroWhatsAppButton() {
  const [href, setHref] = useState<string>(() =>
    buildWhatsAppApiHref(
      `Hi, I want to know more about ${WHATSAPP_STORE_NAME} smart home and business automation solutions. ${WHATSAPP_STORE_NAME}`,
    ),
  );

  useEffect(() => {
    const url = typeof window !== "undefined" ? window.location.href : "";
    const text = `Hi, I want to know more about ${WHATSAPP_STORE_NAME} smart home and business automation solutions.${url ? ` ${url}` : ""} ${WHATSAPP_STORE_NAME}`;
    setHref(buildWhatsAppApiHref(text));
  }, []);

  return (
    <Button
      asChild
      variant="link"
      className="h-auto gap-1 px-2 py-1 text-white hover:text-white/90"
    >
      <a
        href={href}
        target="_blank"
        rel="noopener noreferrer"
        aria-label="Get software solution — contact on WhatsApp"
      >
        <Info className="size-4 shrink-0" />
        Get Software Solution
      </a>
    </Button>
  );
}
