"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/hooks/useRecommendedClassDrafts.ts
var useRecommendedClassDrafts_exports = {};
__export(useRecommendedClassDrafts_exports, {
  DEFAULT_RECOMMENDED_CLASS_DRAFTS_PAGINATION: () => DEFAULT_RECOMMENDED_CLASS_DRAFTS_PAGINATION,
  createRecommendedClassDraftsHook: () => createRecommendedClassDraftsHook,
  createUseRecommendedClassDrafts: () => createUseRecommendedClassDrafts,
  handleRecommendedClassDraftFetchError: () => handleRecommendedClassDraftFetchError
});
module.exports = __toCommonJS(useRecommendedClassDrafts_exports);
var import_react2 = require("react");

// src/hooks/useRecommendedClassModels.ts
var import_react = require("react");
var import_zod2 = require("zod");
var import_dayjs = __toESM(require("dayjs"));

// src/types/recommendedLessons.ts
var RECOMMENDED_CLASS_FILTER_STATUS_OPTIONS = [
  { id: "VENCIDA" /* VENCIDA */, name: "Vencida" },
  { id: "A_VENCER" /* A_VENCER */, name: "Ativa" }
];
var RECOMMENDED_CLASS_STATUS_OPTIONS = [
  { id: "A_VENCER" /* A_VENCER */, name: "A Vencer" },
  { id: "VENCIDA" /* VENCIDA */, name: "Vencida" },
  { id: "CONCLUIDA" /* CONCLUIDA */, name: "Conclu\xEDda" }
];
var RecommendedClassDraftType = /* @__PURE__ */ ((RecommendedClassDraftType2) => {
  RecommendedClassDraftType2["MODELO"] = "MODELO";
  RecommendedClassDraftType2["RASCUNHO"] = "RASCUNHO";
  return RecommendedClassDraftType2;
})(RecommendedClassDraftType || {});

// src/utils/hookErrorHandler.ts
var import_zod = require("zod");
var createFetchErrorHandler = (validationErrorMessage, genericErrorMessage) => (error) => {
  if (error instanceof import_zod.z.ZodError) {
    console.error(validationErrorMessage, error);
    return validationErrorMessage;
  }
  console.error(genericErrorMessage, error);
  return genericErrorMessage;
};

// src/hooks/useRecommendedClassModels.ts
var recommendedClassModelResponseSchema = import_zod2.z.object({
  id: import_zod2.z.string().uuid(),
  type: import_zod2.z.nativeEnum(RecommendedClassDraftType),
  title: import_zod2.z.string(),
  description: import_zod2.z.string().nullable(),
  creatorUserInstitutionId: import_zod2.z.string().uuid(),
  subjectId: import_zod2.z.string().uuid().nullable(),
  subject: import_zod2.z.object({ id: import_zod2.z.string(), name: import_zod2.z.string() }).nullable().optional(),
  startDate: import_zod2.z.string().nullable(),
  finalDate: import_zod2.z.string().nullable(),
  createdAt: import_zod2.z.string(),
  updatedAt: import_zod2.z.string(),
  // Activity drafts attached to this model. Kept in the schema so Zod
  // preserves the field during validation — used to derive
  // activityDraftsCount for the send-modal "Permitir refazer?" gate.
  activityDrafts: import_zod2.z.array(
    import_zod2.z.object({
      activityDraftId: import_zod2.z.uuid(),
      sequence: import_zod2.z.number(),
      title: import_zod2.z.string().nullable().optional()
    })
  ).optional().default([])
});
var recommendedClassModelsApiResponseSchema = import_zod2.z.object({
  message: import_zod2.z.string(),
  data: import_zod2.z.object({
    drafts: import_zod2.z.array(recommendedClassModelResponseSchema),
    total: import_zod2.z.number()
  })
});
var transformRecommendedClassModelToTableItem = (model, subjectsMap) => {
  const subjectName = model.subject?.name || (model.subjectId ? subjectsMap?.get(model.subjectId) || "" : "");
  return {
    id: model.id,
    title: model.title || "Sem t\xEDtulo",
    savedAt: (0, import_dayjs.default)(model.createdAt).format("DD/MM/YYYY"),
    subject: subjectName,
    subjectId: model.subjectId,
    activityDraftsCount: model.activityDrafts?.length ?? 0
  };
};
var handleRecommendedClassModelFetchError = createFetchErrorHandler(
  "Erro ao validar dados de modelos de aulas",
  "Erro ao carregar modelos de aulas"
);

// src/hooks/useRecommendedClassDrafts.ts
var DEFAULT_RECOMMENDED_CLASS_DRAFTS_PAGINATION = {
  total: 0,
  page: 1,
  limit: 10,
  totalPages: 0
};
var handleRecommendedClassDraftFetchError = createFetchErrorHandler(
  "Erro ao validar dados de rascunhos de aulas",
  "Erro ao carregar rascunhos de aulas"
);
var createUseRecommendedClassDrafts = (apiClient) => {
  return () => {
    const [state, setState] = (0, import_react2.useState)({
      models: [],
      loading: false,
      error: null,
      pagination: DEFAULT_RECOMMENDED_CLASS_DRAFTS_PAGINATION
    });
    const fetchModels = (0, import_react2.useCallback)(
      async (filters, subjectsMap) => {
        setState((prev) => ({ ...prev, loading: true, error: null }));
        try {
          const response = await apiClient.get(
            "/recommended-class/drafts",
            { params: filters }
          );
          const validatedData = recommendedClassModelsApiResponseSchema.parse(
            response.data
          );
          const tableItems = validatedData.data.drafts.map(
            (draft) => transformRecommendedClassModelToTableItem(draft, subjectsMap)
          );
          const limit = filters?.limit || 10;
          const page = filters?.page || 1;
          const total = validatedData.data.total;
          const totalPages = Math.ceil(total / limit);
          setState({
            models: tableItems,
            loading: false,
            error: null,
            pagination: {
              total,
              page,
              limit,
              totalPages
            }
          });
        } catch (error) {
          const errorMessage = handleRecommendedClassDraftFetchError(error);
          setState((prev) => ({
            ...prev,
            loading: false,
            error: errorMessage
          }));
        }
      },
      [apiClient]
    );
    const deleteModel = (0, import_react2.useCallback)(
      async (id) => {
        try {
          await apiClient.delete(`/recommended-class/drafts/${id}`);
          return true;
        } catch (error) {
          console.error("Erro ao deletar rascunho:", error);
          return false;
        }
      },
      [apiClient]
    );
    return {
      ...state,
      fetchModels,
      deleteModel
    };
  };
};
var createRecommendedClassDraftsHook = createUseRecommendedClassDrafts;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  DEFAULT_RECOMMENDED_CLASS_DRAFTS_PAGINATION,
  createRecommendedClassDraftsHook,
  createUseRecommendedClassDrafts,
  handleRecommendedClassDraftFetchError
});
//# sourceMappingURL=index.js.map