"use client";

import { useCallback, useState } from "react";
import type { InlineAlertType } from "@/components/ui/inline-alert";

export interface ActionFeedback {
  type: InlineAlertType;
  message: string;
  title?: string;
}

/** 直接操作（儲存、刪除、驗證）用頁面內提示；AI／背景任務才進通知中心。 */
export function useActionFeedback() {
  const [feedback, setFeedback] = useState<ActionFeedback | null>(null);

  const clearFeedback = useCallback(() => setFeedback(null), []);

  const showError = useCallback((message: string, title?: string) => {
    setFeedback({ type: "error", message, title });
  }, []);

  const showSuccess = useCallback((message: string, title?: string) => {
    setFeedback({ type: "success", message, title });
  }, []);

  const showWarning = useCallback((message: string, title?: string) => {
    setFeedback({ type: "warning", message, title });
  }, []);

  const showInfo = useCallback((message: string, title?: string) => {
    setFeedback({ type: "info", message, title });
  }, []);

  return {
    feedback,
    clearFeedback,
    showError,
    showSuccess,
    showWarning,
    showInfo,
  };
}