import { createContext, useContext, useState } from "react";

interface LogDetail {
  id: number;
  username: string;
  name: string;
  amount: number;
  remark: string;
  inquiry_response: string;
  payment_response: string;
  response_message: string;
  status: string;
  process_date: string;
  reference_number: string;
  additional_info: string;
}

interface TransactionDialogContextProps {
  showLogDialog: boolean;
  selectedLog: LogDetail | null;
  setShowLogDialog: (val: boolean) => void;
  setSelectedLog: (log: LogDetail | null) => void;
}

const TransactionDialogContext = createContext<TransactionDialogContextProps | undefined>(undefined);

export const TransactionDialogProvider = ({ children }: { children: React.ReactNode }) => {
  const [showLogDialog, setShowLogDialog] = useState(false);
  const [selectedLog, setSelectedLog] = useState<LogDetail | null>(null);

  return (
    <TransactionDialogContext.Provider value={{ showLogDialog, setShowLogDialog, selectedLog, setSelectedLog }}>
      {children}
    </TransactionDialogContext.Provider>
  );
};

export const useTransactionDialog = () => {
  const context = useContext(TransactionDialogContext);
  if (!context) throw new Error("useTransactionDialog must be used within TransactionDialogProvider");
  return context;
};
