"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/SendActivityModal/validation.ts
var validation_exports = {};
__export(validation_exports, {
  ERROR_MESSAGES: () => ERROR_MESSAGES,
  activityStepSchema: () => activityStepSchema,
  deadlineStepSchema: () => deadlineStepSchema,
  isFormValid: () => isFormValid,
  isStepValid: () => isStepValid,
  recipientStepSchema: () => recipientStepSchema,
  validateActivityStep: () => validateActivityStep,
  validateDeadlineStep: () => validateDeadlineStep,
  validateRecipientStep: () => validateRecipientStep,
  validateStep: () => validateStep
});
module.exports = __toCommonJS(validation_exports);
var import_zod = require("zod");
var ERROR_MESSAGES = {
  SUBTYPE_REQUIRED: "Campo obrigat\xF3rio! Por favor, selecione uma op\xE7\xE3o para continuar.",
  MODE_REQUIRED: "Campo obrigat\xF3rio! Por favor, selecione o modo de prova para continuar.",
  TITLE_REQUIRED: "Campo obrigat\xF3rio! Por favor, preencha este campo para continuar.",
  STUDENTS_REQUIRED: "Campo obrigat\xF3rio! Por favor, selecione pelo menos um aluno para continuar.",
  START_DATE_REQUIRED: "Campo obrigat\xF3rio! Por favor, preencha este campo para continuar.",
  FINAL_DATE_REQUIRED: "Campo obrigat\xF3rio! Por favor, preencha este campo para continuar.",
  FINAL_DATE_INVALID: "A data final deve ser maior ou igual \xE0 data inicial."
};
var activityStepSchema = import_zod.z.object({
  subtype: import_zod.z.enum(
    ["TAREFA" /* TAREFA */, "TRABALHO" /* TRABALHO */, "PROVA" /* PROVA */],
    { error: () => ERROR_MESSAGES.SUBTYPE_REQUIRED }
  ),
  title: import_zod.z.string({ error: () => ERROR_MESSAGES.TITLE_REQUIRED }).transform((val) => val.trim()).refine((val) => val.length > 0, {
    message: ERROR_MESSAGES.TITLE_REQUIRED
  }),
  notification: import_zod.z.string().optional()
});
var recipientStepSchema = import_zod.z.object({
  students: import_zod.z.array(
    import_zod.z.object({
      studentId: import_zod.z.string(),
      userInstitutionId: import_zod.z.string()
    }),
    {
      error: () => ERROR_MESSAGES.STUDENTS_REQUIRED
    }
  ).min(1, ERROR_MESSAGES.STUDENTS_REQUIRED)
});
var DATE_REGEX = /^\d{4}-\d{2}-\d{2}$/;
var TIME_REGEX = /^\d{2}:\d{2}$/;
var deadlineStepBaseSchema = import_zod.z.object({
  startDate: import_zod.z.string({
    error: () => ERROR_MESSAGES.START_DATE_REQUIRED
  }).min(1, ERROR_MESSAGES.START_DATE_REQUIRED).regex(DATE_REGEX, ERROR_MESSAGES.START_DATE_REQUIRED),
  startTime: import_zod.z.string().regex(TIME_REGEX).default("00:00"),
  finalDate: import_zod.z.string({
    error: () => ERROR_MESSAGES.FINAL_DATE_REQUIRED
  }).min(1, ERROR_MESSAGES.FINAL_DATE_REQUIRED).regex(DATE_REGEX, ERROR_MESSAGES.FINAL_DATE_REQUIRED),
  finalTime: import_zod.z.string().regex(TIME_REGEX).default("23:59"),
  canRetry: import_zod.z.boolean().default(false)
});
var deadlineStepSchema = deadlineStepBaseSchema.refine(
  (data) => {
    const start = /* @__PURE__ */ new Date(`${data.startDate}T${data.startTime}`);
    const end = /* @__PURE__ */ new Date(`${data.finalDate}T${data.finalTime}`);
    return end >= start;
  },
  { message: ERROR_MESSAGES.FINAL_DATE_INVALID, path: ["finalDate"] }
);
function validateActivityStep(data, options) {
  const errors = {};
  if (options?.enableExamMode) {
    if (!data.title || data.title.trim().length === 0) {
      errors.title = ERROR_MESSAGES.TITLE_REQUIRED;
    }
    return errors;
  }
  const result = activityStepSchema.safeParse({
    subtype: data.subtype,
    title: data.title,
    notification: data.notification
  });
  if (!result.success) {
    result.error.issues.forEach((issue) => {
      const field = issue.path[0];
      if (field === "subtype" || field === "title") {
        errors[field] = issue.message;
      }
    });
  }
  if (options?.enableExamMode && data.subtype === "PROVA" /* PROVA */ && !data.mode) {
    errors.mode = ERROR_MESSAGES.MODE_REQUIRED;
  }
  return errors;
}
function validateRecipientStep(data) {
  const errors = {};
  const result = recipientStepSchema.safeParse({
    students: data.students ?? []
  });
  if (!result.success) {
    result.error.issues.forEach((issue) => {
      if (issue.path[0] === "students") {
        errors.students = issue.message;
      }
    });
  }
  return errors;
}
function validateDeadlineStep(data, options) {
  const errors = {};
  if (options?.enableExamMode) {
    if (!data.startDate) {
      errors.startDate = ERROR_MESSAGES.START_DATE_REQUIRED;
    }
    return errors;
  }
  if (!data.startDate) {
    errors.startDate = ERROR_MESSAGES.START_DATE_REQUIRED;
  }
  if (!data.finalDate) {
    errors.finalDate = ERROR_MESSAGES.FINAL_DATE_REQUIRED;
  }
  if (data.startDate && data.finalDate) {
    const result = deadlineStepSchema.safeParse({
      startDate: data.startDate,
      startTime: data.startTime ?? "00:00",
      finalDate: data.finalDate,
      finalTime: data.finalTime ?? "23:59",
      canRetry: data.canRetry ?? false
    });
    if (!result.success) {
      result.error.issues.forEach((issue) => {
        const field = issue.path[0];
        if (field === "startDate" || field === "finalDate") {
          errors[field] = issue.message;
        }
      });
    }
  }
  return errors;
}
function validateStep(step, data, options) {
  switch (step) {
    case 1:
      return validateActivityStep(data, options);
    case 2:
      return validateRecipientStep(data);
    case 3:
      return validateDeadlineStep(data, options);
    default:
      return {};
  }
}
function isStepValid(step, data, options) {
  const errors = validateStep(step, data, options);
  return Object.keys(errors).length === 0;
}
function isFormValid(data, options) {
  return isStepValid(1, data, options) && isStepValid(2, data) && isStepValid(3, data, options);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  ERROR_MESSAGES,
  activityStepSchema,
  deadlineStepSchema,
  isFormValid,
  isStepValid,
  recipientStepSchema,
  validateActivityStep,
  validateDeadlineStep,
  validateRecipientStep,
  validateStep
});
//# sourceMappingURL=validation.js.map