/**
 * Test utilities: custom render with app store and optional providers.
 */

import React, { ReactElement } from "react";
import { render, RenderOptions } from "@testing-library/react";
import { useAppStore } from "@/store/app-store";

/** Reset app store to a known state before tests that need it. */
export function resetAppStore() {
  const state = useAppStore.getState();
  state.setLang("en");
  state.setCurrentMonth(new Date(2025, 0, 1)); // Feb 2025
  state.setDuties([]);
  state.setCalendarEvents([]);
  state.setLoading(false);
  state.setError(null);
  state.setAccessDenied(false);
  state.setCurrentView("calendar");
  state.setSelectedDay(null);
  state.batchUpdate({ dataForMonthKey: null });
}

function AllTheProviders({ children }: { children: React.ReactNode }) {
  return <>{children}</>;
}

function customRender(ui: ReactElement, options?: Omit<RenderOptions, "wrapper">) {
  return render(ui, {
    wrapper: AllTheProviders,
    ...options,
  });
}

export { customRender as render };
