export async function fetchTodayJalali(): Promise<number> {
  const res = await fetch("/api/today-jalali");
  if (!res.ok) throw new Error(`Failed to fetch today_jalali: ${res.status}`);
  const data = await res.json();
  return data.today_jalali;
}

export async function fetchDailyG(): Promise<any> {
  const res = await fetch("/api/daily-g");
  if (!res.ok) throw new Error(`Failed to fetch daily_g: ${res.status}`);
  return res.json();
}

export async function fetchCheckboxes(jalaliDate: number): Promise<any> {
  const res = await fetch(`/api/checkboxes?jalali_date=${jalaliDate}`);
  if (!res.ok) throw new Error(`Failed to fetch checkboxes: ${res.status}`);
  return res.json();
}

export async function saveCheckboxes(
  jalaliDate: number,
  data: Record<string, boolean>
): Promise<void> {
  await fetch(`/api/checkboxes`, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ date: jalaliDate, data }),
  });
}

export async function status2print(rowIndexes: number[]): Promise<void> {
  await fetch(`/api/status2print`, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(rowIndexes),
  });
}
