import React from "react";
import NotificationI from "ui/domain/uiNotificationEntity";
import { UIStore } from "ui/domain/uiStore";
import { clearNotificationsUseCase } from "ui/useCases/clearNotificationsUseCase";
import {
  notifyDismissibleUseCase,
  notifyUseCase,
} from "ui/useCases/notifyUseCase";
import { removeNotificationUseCase } from "ui/useCases/removeNotificationUseCase";

function useUINotifications(store: UIStore) {
  /* -------------------------------- Searchbar ------------------------------- */
  const push = React.useCallback(
    function (notification: Omit<NotificationI, "uid">) {
      return notifyUseCase(
        {
          notify: store.notify,
        },
        notification
      );
    },
    [store.notify]
  );
  const pushDismissible = React.useCallback(
    function (notification: Omit<NotificationI, "uid" | "delay">) {
      return notifyDismissibleUseCase(
        {
          notify: store.notify,
        },
        notification
      );
    },
    [store.notify]
  );

  const remove = React.useCallback(
    (uid: NotificationI["uid"]) => {
      return removeNotificationUseCase(
        {
          removeNotification: store.removeNotification,
        },
        uid
      );
    },
    [store.removeNotification]
  );

  const removeAll = React.useCallback(() => {
    return clearNotificationsUseCase({
      clearNotifications: store.clearNotifications,
    });
  }, [store.clearNotifications]);

  return {
    /* ------------------------------ Notifications ----------------------------- */
    notifications: store.notifications,
    push,
    pushDismissible,
    remove,
    removeAll,
  };
}

export { useUINotifications };
