// src/utils/utils.ts
import { clsx } from "clsx";
import { twMerge } from "tailwind-merge";

// src/utils/dropdown.ts
var syncDropdownState = (open, isActive, setActiveStates, key) => {
  if (!open && isActive) {
    setActiveStates((prev) => ({ ...prev, [key]: false }));
  }
};

// src/utils/arraysEqual.ts
function arraysEqual(a, b, comparator) {
  if (a.length !== b.length) return false;
  if (a.length === 0 && b.length === 0) return true;
  if (comparator) {
    const sortedA2 = [...a].sort(comparator);
    const sortedB2 = [...b].sort(comparator);
    return sortedA2.every((val, index) => val === sortedB2[index]);
  }
  const sortedA = [...a].sort((x, y) => String(x).localeCompare(String(y)));
  const sortedB = [...b].sort((x, y) => String(x).localeCompare(String(y)));
  return sortedA.every((val, index) => val === sortedB[index]);
}

// src/utils/activityFilters.ts
function getSelectedIdsFromCategories(categories, keys) {
  const result = {};
  for (const [outputKey, categoryKey] of Object.entries(keys)) {
    const category = categories.find((c) => c.key === categoryKey);
    result[outputKey] = category?.selectedIds || [];
  }
  return result;
}
function toggleArrayItem(array, item) {
  return array.includes(item) ? array.filter((i) => i !== item) : [...array, item];
}
function toggleSingleValue(currentValue, newValue) {
  return currentValue === newValue ? null : newValue;
}
function areFiltersEqual(filters1, filters2) {
  if (filters1 === filters2) return true;
  if (!filters1 || !filters2) return false;
  return arraysEqual(filters1.types, filters2.types) && arraysEqual(filters1.bankIds, filters2.bankIds) && arraysEqual(filters1.yearIds, filters2.yearIds) && arraysEqual(filters1.subjectIds, filters2.subjectIds) && arraysEqual(filters1.topicIds, filters2.topicIds) && arraysEqual(filters1.subtopicIds, filters2.subtopicIds) && arraysEqual(filters1.contentIds, filters2.contentIds);
}

// src/utils/questionTypeUtils.ts
function mapQuestionTypeToEnum(type, fallback) {
  const upperType = type.toUpperCase();
  const typeMap = {
    ALTERNATIVA: "ALTERNATIVA" /* ALTERNATIVA */,
    DISSERTATIVA: "DISSERTATIVA" /* DISSERTATIVA */,
    MULTIPLA_ESCOLHA: "MULTIPLA_ESCOLHA" /* MULTIPLA_ESCOLHA */,
    VERDADEIRO_FALSO: "VERDADEIRO_FALSO" /* VERDADEIRO_FALSO */,
    IMAGEM: "IMAGEM" /* IMAGEM */,
    RELACIONAR: "RELACIONAR" /* RELACIONAR */,
    PREENCHER_LACUNAS: "PREENCHER_LACUNAS" /* PREENCHER_LACUNAS */
  };
  return typeMap[upperType] ?? fallback ?? null;
}
function mapQuestionTypeToEnumRequired(type, fallback = "ALTERNATIVA" /* ALTERNATIVA */) {
  return mapQuestionTypeToEnum(type, fallback) ?? fallback;
}

// src/utils/activityDetailsUtils.ts
import dayjs from "dayjs";

// src/types/activityDetails.ts
import { z } from "zod";
var STUDENT_ACTIVITY_STATUS = {
  CONCLUIDO: "CONCLUIDO",
  AGUARDANDO_CORRECAO: "AGUARDANDO_CORRECAO",
  AGUARDANDO_RESPOSTA: "AGUARDANDO_RESPOSTA",
  NAO_ENTREGUE: "NAO_ENTREGUE",
  /** Physical test (presencial): student hasn't submitted the answer sheet yet */
  AWAITING_ANSWER_SHEET: "AGUARDANDO_GABARITO",
  /** Physical test (presencial): answer sheet has been received and processed */
  ANSWER_SHEET_RECEIVED: "GABARITO_RECEBIDO"
};
var studentActivityStatusSchema = z.enum([
  STUDENT_ACTIVITY_STATUS.CONCLUIDO,
  STUDENT_ACTIVITY_STATUS.AGUARDANDO_CORRECAO,
  STUDENT_ACTIVITY_STATUS.AGUARDANDO_RESPOSTA,
  STUDENT_ACTIVITY_STATUS.NAO_ENTREGUE,
  STUDENT_ACTIVITY_STATUS.AWAITING_ANSWER_SHEET,
  STUDENT_ACTIVITY_STATUS.ANSWER_SHEET_RECEIVED
]);

// src/utils/activityDetailsUtils.ts
var getStatusBadgeConfig = (status) => {
  const configs = {
    [STUDENT_ACTIVITY_STATUS.CONCLUIDO]: {
      label: "Conclu\xEDdo",
      bgColor: "bg-green-50",
      textColor: "text-green-800"
    },
    [STUDENT_ACTIVITY_STATUS.AGUARDANDO_CORRECAO]: {
      label: "Aguardando Corre\xE7\xE3o",
      bgColor: "bg-yellow-50",
      textColor: "text-yellow-800"
    },
    [STUDENT_ACTIVITY_STATUS.AGUARDANDO_RESPOSTA]: {
      label: "Aguardando Resposta",
      bgColor: "bg-blue-50",
      textColor: "text-blue-800"
    },
    [STUDENT_ACTIVITY_STATUS.NAO_ENTREGUE]: {
      label: "N\xE3o Entregue",
      bgColor: "bg-red-50",
      textColor: "text-red-800"
    },
    [STUDENT_ACTIVITY_STATUS.AWAITING_ANSWER_SHEET]: {
      label: "Aguardando Gabarito",
      bgColor: "bg-sky-50",
      textColor: "text-sky-700"
    },
    [STUDENT_ACTIVITY_STATUS.ANSWER_SHEET_RECEIVED]: {
      label: "Gabarito Recebido",
      bgColor: "bg-emerald-50",
      textColor: "text-emerald-800"
    }
  };
  return configs[status] ?? {
    label: status,
    bgColor: "bg-gray-50",
    textColor: "text-gray-700"
  };
};
var formatTimeSpent = (seconds) => {
  const totalSeconds = Math.floor(Math.abs(seconds));
  const hours = Math.floor(totalSeconds / 3600);
  const minutes = Math.floor(totalSeconds % 3600 / 60);
  const secs = totalSeconds % 60;
  return `${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}:${String(secs).padStart(2, "0")}`;
};
var formatQuestionNumbers = (numbers) => {
  if (numbers.length === 0) return "-";
  return numbers.map((n) => String(n).padStart(2, "0")).join(", ");
};
var formatDateToBrazilian = (dateString) => {
  const date = new Date(dateString);
  const day = String(date.getUTCDate()).padStart(2, "0");
  const month = String(date.getUTCMonth() + 1).padStart(2, "0");
  const year = date.getUTCFullYear();
  return `${day}/${month}/${year}`;
};
var formatActivityDateToBrazilian = (dateString) => {
  return dayjs(dateString).format("DD/MM/YYYY");
};

// src/utils/formatScore.ts
function formatScore(value, scoreType) {
  if (scoreType === "tri" /* TRI */) {
    return Math.round(value).toString();
  }
  return `${value.toFixed(1).replace(".", ",")}%`;
}

// src/utils/utils.ts
function cn(...inputs) {
  return twMerge(clsx(inputs));
}
function formatPercentageRounded(value) {
  return `${Math.round(value)}%`;
}
function hexToRgba(hex, opacity) {
  const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
  if (!result) return `rgba(107, 114, 128, ${opacity})`;
  const r = Number.parseInt(result[1], 16);
  const g = Number.parseInt(result[2], 16);
  const b = Number.parseInt(result[3], 16);
  return `rgba(${r}, ${g}, ${b}, ${opacity})`;
}
function bgClassToCssVar(bgClass) {
  return `var(--color-${bgClass.replace("bg-", "")})`;
}
function polarToCartesian(cx, cy, r, angleDeg) {
  const rad = (angleDeg - 90) * Math.PI / 180;
  return { x: cx + r * Math.cos(rad), y: cy + r * Math.sin(rad) };
}
function describeArc(cx, cy, r, startAngle, endAngle) {
  const span = endAngle - startAngle;
  if (span >= 359.99) {
    const midAngle = startAngle + 180;
    const s2 = polarToCartesian(cx, cy, r, startAngle);
    const m = polarToCartesian(cx, cy, r, midAngle);
    return `M ${cx} ${cy} L ${s2.x} ${s2.y} A ${r} ${r} 0 1 1 ${m.x} ${m.y} A ${r} ${r} 0 1 1 ${s2.x} ${s2.y} Z`;
  }
  const s = polarToCartesian(cx, cy, r, endAngle);
  const e = polarToCartesian(cx, cy, r, startAngle);
  const largeArc = span > 180 ? 1 : 0;
  return `M ${cx} ${cy} L ${s.x} ${s.y} A ${r} ${r} 0 ${largeArc} 0 ${e.x} ${e.y} Z`;
}
function getSubjectColorWithOpacity(hexColor, isDark) {
  if (!hexColor) return void 0;
  let color = hexColor.replace(/^#/, "").toLowerCase();
  if (isDark) {
    if (color.length === 8) {
      color = color.slice(0, 6);
    }
    return `#${color}`;
  } else {
    let resultColor;
    if (color.length === 6) {
      resultColor = `#${color}4d`;
    } else if (color.length === 8) {
      resultColor = `#${color}`;
    } else {
      resultColor = `#${color}`;
    }
    return resultColor;
  }
}
export {
  areFiltersEqual,
  bgClassToCssVar,
  cn,
  describeArc,
  formatActivityDateToBrazilian,
  formatDateToBrazilian,
  formatPercentageRounded,
  formatQuestionNumbers,
  formatScore,
  formatTimeSpent,
  getSelectedIdsFromCategories,
  getStatusBadgeConfig,
  getSubjectColorWithOpacity,
  hexToRgba,
  mapQuestionTypeToEnum,
  mapQuestionTypeToEnumRequired,
  polarToCartesian,
  syncDropdownState,
  toggleArrayItem,
  toggleSingleValue
};
//# sourceMappingURL=index.mjs.map