"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
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/reactnative/index.ts
var reactnative_exports = {};
__export(reactnative_exports, {
  DEFAULT_FEEDBACK_OPTIONS: () => DEFAULT_FEEDBACK_OPTIONS,
  DEFAULT_GOOD_RATING_THRESHOLD: () => DEFAULT_GOOD_RATING_THRESHOLD,
  DEFAULT_LABELS: () => DEFAULT_LABELS,
  DEFAULT_THEME: () => DEFAULT_THEME,
  buildSubmitPayload: () => buildSubmitPayload,
  getFeedbackQuestion: () => getFeedbackQuestion,
  getLabels: () => getLabels,
  getQuestionForRating: () => getQuestionForRating,
  getRatingSentiment: () => getRatingSentiment,
  getTheme: () => getTheme,
  isOthersOption: () => isOthersOption,
  normalizeFeedbackOptions: () => normalizeFeedbackOptions,
  validateRatingForm: () => validateRatingForm
});
module.exports = __toCommonJS(reactnative_exports);

// src/shared/defaults.ts
var DEFAULT_GOOD_RATING_THRESHOLD = 4;
var DEFAULT_FEEDBACK_OPTIONS = [
  "Akurasi & Relevansi Modul",
  "Durasi Materi",
  "Audio/Desain Visual",
  "Others"
];
var DEFAULT_THEME = {
  primaryColor: "#9B0008",
  starColor: "#FFD45A",
  inactiveStarColor: "#E5E5E5",
  textColor: "#222222",
  mutedTextColor: "#555555",
  buttonTextColor: "#FFFFFF",
  courseButtonColor: "#2E2E2E",
  backgroundColor: "#FFFFFF",
  borderColor: "#DDDDDD",
  borderRadius: 24
};
var DEFAULT_LABELS = {
  id: {
    title: "Waktunya beri feedback!",
    description: "",
    ratingAriaLabel: "Rating course",
    closeLabel: "Tutup rating",
    impressiveQuestion: "Apa saja yang membuatmu terkesan?",
    improvementQuestion: "Apa saja yang harus kami perbaiki?",
    otherQuestion: "Apa yang bisa kami lakukan untuk meningkatkan pembelajaran ini?",
    submit: "Submit",
    successTitle: "Terima kasih telah meluangkan waktu untuk mengisi evaluasi ini",
    successDescription: "Masukan yang Anda berikan sangat berarti bagi kami.",
    backToHome: "Kembali ke home",
    nextCourse: "Lanjut course",
    others: "Others",
    loading: "Mengirim...",
    submitError: "Gagal mengirim rating. Silakan coba lagi.",
    otherInputQuestion: "Keterangan lainnya?",
    otherImpressedQuestion: "Sebutkan Aspek Lain Yang Membuatmu Terkesan?",
    otherImprovementQuestion: "Sebutkan Aspek Lain Yang Perlu Diperbaiki?",
    feedbackImpressedQuestion: "Apa yang membuatmu terkesan?",
    feedbackImprovementQuestion: "Apa yang bisa kami tingkatkan untuk meningkatkan pembelajaran ini?"
  },
  en: {
    title: "Time to share your feedback!",
    description: "",
    ratingAriaLabel: "Course rating",
    closeLabel: "Close rating",
    impressiveQuestion: "What impressed you?",
    improvementQuestion: "What should we improve?",
    otherQuestion: "What can we do to improve this learning experience?",
    submit: "Submit",
    successTitle: "Thank you for taking the time to complete this evaluation",
    successDescription: "Your feedback means a lot to us.",
    backToHome: "Back to home",
    nextCourse: "Next course",
    others: "Others",
    loading: "Submitting...",
    submitError: "Failed to submit rating. Please try again.",
    otherInputQuestion: "Other details?",
    otherImpressedQuestion: "Mention other aspects that impressed you.",
    otherImprovementQuestion: "Mention other aspects that need improvement.",
    feedbackImpressedQuestion: "What impressed you?",
    feedbackImprovementQuestion: "What can we improve to enhance this learning experience?"
  }
};
function getLabels(language = "id", overrides) {
  return __spreadValues(__spreadValues({}, DEFAULT_LABELS[language]), overrides);
}
function getTheme(overrides) {
  return __spreadValues(__spreadValues({}, DEFAULT_THEME), overrides);
}

// src/shared/options.ts
function normalizeFeedbackOptions(options, othersLabel = "Others") {
  const normalized = ((options == null ? void 0 : options.length) ? options : DEFAULT_FEEDBACK_OPTIONS).map((option) => option.trim()).filter(Boolean);
  const hasOthers = normalized.some(
    (option) => isOthersOption(option, othersLabel)
  );
  return Array.from(new Set(hasOthers ? normalized : [...normalized, othersLabel]));
}
function isOthersOption(option, othersLabel = "Others") {
  const val = option.trim().toLowerCase();
  const normalizedOthersLabel = othersLabel.trim().toLowerCase();
  return val === normalizedOthersLabel || val.includes("other") || val.includes("lainnya");
}

// src/shared/payload.ts
function buildSubmitPayload(input) {
  var _a, _b, _c;
  const otherText = ((_a = input.otherText) == null ? void 0 : _a.trim()) || null;
  const isOtherSelected = input.selectedReasons.some(
    (reason) => isOthersOption(reason, input.labels.others)
  );
  const isImprovementRating = input.rating < ((_b = input.goodRatingThreshold) != null ? _b : DEFAULT_GOOD_RATING_THRESHOLD);
  const feedbackText = isImprovementRating ? ((_c = input.feedbackText) == null ? void 0 : _c.trim()) || null : null;
  const selectedTagIds = [];
  input.selectedReasons.forEach((reason) => {
    var _a2;
    const tag = (_a2 = input.course.tags) == null ? void 0 : _a2.find((t) => t.label === reason);
    if (tag && tag.id !== null) {
      selectedTagIds.push(tag.id);
    }
  });
  return {
    courseId: input.course.id,
    setting_id: input.course.setting_id || 0,
    star_rating: input.rating,
    selected_tag_ids: selectedTagIds,
    is_other_selected: isOtherSelected,
    other_text: otherText,
    feedback_text: feedbackText
  };
}

// src/shared/rating.ts
function getRatingSentiment(rating, goodRatingThreshold = DEFAULT_GOOD_RATING_THRESHOLD) {
  return rating >= goodRatingThreshold ? "impressed" : "improvement";
}
function getQuestionForRating(rating, labels, goodRatingThreshold = DEFAULT_GOOD_RATING_THRESHOLD, customTitle) {
  if (customTitle) return customTitle;
  return getRatingSentiment(rating, goodRatingThreshold) === "impressed" ? labels.impressiveQuestion : labels.improvementQuestion;
}
function getFeedbackQuestion(rating, labels, goodRatingThreshold = DEFAULT_GOOD_RATING_THRESHOLD) {
  return getRatingSentiment(rating, goodRatingThreshold) === "impressed" ? labels.feedbackImpressedQuestion : labels.feedbackImprovementQuestion;
}

// src/shared/validation.ts
function validateRatingForm(state, othersLabel = "Others") {
  var _a, _b;
  const hasRating = typeof state.rating === "number" && state.rating >= 1 && state.rating <= 5;
  const hasReason = state.selectedReasons.length > 0;
  const needsOtherText = state.selectedReasons.some(
    (reason) => isOthersOption(reason, othersLabel)
  );
  const hasOtherText = Boolean((_a = state.otherText) == null ? void 0 : _a.trim());
  const hasFeedbackText = Boolean((_b = state.feedbackText) == null ? void 0 : _b.trim());
  return {
    isValid: hasRating && hasReason && (!needsOtherText || hasOtherText),
    hasRating,
    hasReason,
    needsOtherText,
    hasOtherText,
    hasFeedbackText
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  DEFAULT_FEEDBACK_OPTIONS,
  DEFAULT_GOOD_RATING_THRESHOLD,
  DEFAULT_LABELS,
  DEFAULT_THEME,
  buildSubmitPayload,
  getFeedbackQuestion,
  getLabels,
  getQuestionForRating,
  getRatingSentiment,
  getTheme,
  isOthersOption,
  normalizeFeedbackOptions,
  validateRatingForm
});
//# sourceMappingURL=index.cjs.map