import { message as staticMessage, notification as staticNotification } from "antd";

let messageApi = staticMessage;
let notificationApi = staticNotification;

const createApiProxy = (getApi) =>
  new Proxy(
    {},
    {
      get(_target, prop) {
        const api = getApi();
        const value = api[prop];
        return typeof value === "function" ? value.bind(api) : value;
      }
    }
  );

export const configureAntdFeedback = ({ message, notification }) => {
  if (message) messageApi = message;
  if (notification) notificationApi = notification;
};

export const antdMessage = createApiProxy(() => messageApi);
export const antdNotification = createApiProxy(() => notificationApi);
