"use client";

import { MessageCircle } from "lucide-react";
import { cn } from "@/lib/utils";

export const LIVECHAT_OPEN_EVENT = "zirabet-livechat-open";
export const LIVECHAT_ENABLED_KEY = "zirabet_livechat_enabled";
export const LIVECHAT_OPEN_KEY = "zirabet_livechat_open";

export function LiveChatOpenButton({ className }: { className?: string }) {
  function openLivechat() {
    window.localStorage.setItem(LIVECHAT_ENABLED_KEY, "1");
    window.localStorage.setItem(LIVECHAT_OPEN_KEY, "1");
    window.dispatchEvent(new CustomEvent(LIVECHAT_OPEN_EVENT));
  }

  return (
    <button
      type="button"
      onClick={openLivechat}
      className={cn("mt-4 inline-flex h-9 items-center gap-2 rounded-lg bg-felt px-3 text-xs font-extrabold text-ink-950", className)}
    >
      <MessageCircle className="h-4 w-4" />
      Ouvrir le livechat
    </button>
  );
}
