import { z } from "zod";
import "@tanstack/react-start";

//#region src/notifications.d.ts

/** What the builder wrote in Studio for the inbox. Any of it may be missing. */
type NotificationTexts = {
  buttonLabel: string | null;
  allTabName: string | null;
  allTabEmptyMessage: string | null;
  unreadTabName: string | null;
  unreadTabEmptyMessage: string | null;
  markAllAsReadLabel: string | null;
  markAsReadLabel: string | null;
  markAsUnreadLabel: string | null;
};
type InAppNotification = {
  id: string;
  title: string | null;
  description: string | null;
  /** Where a click should take the visitor. A path in the app, or a full URL. */
  link: string | null;
  read: boolean;
  /** Milliseconds since the epoch. */
  createdAt: number | null;
};
type InAppNotifications = /** Loading, signed out, or in-app notifications off for this app. */
{
  status: "unavailable";
} | {
  status: "ready";
  texts: NotificationTexts;
  /** The app's square logo or favicon, for a notification no person sent. */
  defaultIcon: string | null;
  /** The loaded notifications, newest first. */
  notifications: Array<InAppNotification>;
  unreadCount: number;
  /** True while only unread notifications are listed. */
  unreadOnly: boolean;
  /** Lists only unread notifications, or all of them again. */
  showUnreadOnly: (unreadOnly: boolean) => void;
  hasMore: boolean;
  /** Loads the next, older page. */
  loadMore: () => Promise<void>;
  markRead: (id: string) => Promise<void>;
  markUnread: (id: string) => Promise<void>;
  markAllRead: () => Promise<void>;
};
/**
 * The signed-in visitor's in-app notifications, sent to them from Softr
 * Workflows. Every component that calls it reads the same list and unread
 * count, and the page polls the count once, however many call it.
 *
 * @example
 * function Inbox() {
 *   const inbox = useNotifications()
 *   if (inbox.status !== "ready") return null
 *   return <button>{inbox.texts.buttonLabel ?? "Notifications"} ({inbox.unreadCount})</button>
 * }
 */
declare function useNotifications(): InAppNotifications;
//#endregion
export { InAppNotification, InAppNotifications, NotificationTexts, useNotifications };