import { create } from "zustand";

interface LoginModalStore {
  open: boolean;
  /** 登录成功后要跳转的路径。空值表示就地刷新当前页。 */
  redirectTo?: string;
  setOpen: (open: boolean) => void;
  /** 唤起登录弹窗。可选传 redirectTo —— 登录成功后会 router.push 过去。 */
  show: (redirectTo?: string) => void;
}

export const useLoginModalStore = create<LoginModalStore>((set) => ({
  open: false,
  redirectTo: undefined,
  setOpen: (open) => set({ open }),
  show: (redirectTo) => set({ open: true, redirectTo }),
}));
