import { create } from "zustand";

export interface BanNoticeDetails {
  ban_reason?: string | null;
  ban_duration_days?: number | null;
  ban_ends_at?: string | null;
  /** `User::banDetails()`: true when the ban has no end date. */
  ban_is_indefinite?: boolean | null;
  contact_email?: string | null;
}
interface BanNoticeState {
  details: BanNoticeDetails | null;
  /** The backend's own text (`msg`), already in the request's language. */
  message: string | null;
  show: (message: string, details?: BanNoticeDetails) => void;
  close: () => void;
}

/**
 * The banned-account popup. Opened from the axios response interceptor
 * whenever the API answers `data.error_code === "user_banned"` — at sign-in
 * (403) or on any request made with a banned account's token (401) — and
 * rendered once, by `BanNoticeModal`.
 */
export const useBanNoticeStore = create<BanNoticeState>((set) => ({
  message: null,
  details: null,
  show: (message, details) => set({ message, details: details ?? null }),
  close: () => set({ message: null, details: null }),
}));
