export function adaptSlots(slotsResponse) {
  const sessions = slotsResponse?.data?.sessions ?? slotsResponse?.sessions ?? [];

  // Group slots by the shifts the backend already returns; the front does not
  // decide shift boundaries (no hard-coded morning/evening split). Each session
  // becomes one tab labelled with its own time range.
  return sessions
    .filter((session) => Array.isArray(session.slots) && session.slots.length > 0)
    .map((session) => ({
      start_time: session.start_time,
      end_time: session.end_time,
      label: `${session.start_time} - ${session.end_time}`,
      slots: session.slots,
    }));
}

// حالت سرویسی: پاسخ appointment-service-slots فقط start_times دارد (همه کافی).
// آن‌ها را در یک session قالب‌بندی می‌کنیم تا مثل حالت اسلاتی رندر شوند.
export function adaptServiceSlots(slotsResponse) {
  const starts =
    slotsResponse?.data?.start_times ?? slotsResponse?.start_times ?? [];
  if (!starts.length) return [];
  return [
    {
      start_time: starts[0].start_time,
      end_time: starts[starts.length - 1].start_time,
      label: "زمان‌های خالی",
      slots: starts.map((s) => ({ ...s, is_available: true })),
    },
  ];
}

export function hasAvailable(slots) {
  return Array.isArray(slots) && slots.some((slot) => slot.is_available);
}
