"use client";
// 回响星核 / Echo Nexus — 成就解锁通知消费者
import { useEffect } from "react";
import { useGameStore } from "@/store/gameStore";
import { useToast } from "@/hooks/use-toast";
import { sfx } from "@/hooks/useAudio";

export function AchievementNotifier() {
  const queue = useGameStore((s) => s._achievementQueue);
  const consume = useGameStore((s) => s.consumeAchievementQueue);
  const { toast } = useToast();

  useEffect(() => {
    if (queue.length === 0) return;
    const items = consume();
    for (const a of items) {
      sfx("achievement");
      toast({
        title: `🏆 成就解锁：${a.name}`,
        description: `${a.desc}　奖励：${a.rewardText}`,
      });
    }
  }, [queue, consume, toast]);

  return null;
}
