const englishFallback = (_key, fallbackOrParams, params) => {
  const template = typeof fallbackOrParams === "string" ? fallbackOrParams : "";
  const resolvedParams = typeof fallbackOrParams === "string" ? params : fallbackOrParams;
  if (!resolvedParams) return template;
  return template.replace(/\{\{(\w+)\}\}|\{(\w+)\}/g, (match, doubleKey, singleKey) => {
    const key = doubleKey ?? singleKey;
    const value = resolvedParams[key];
    return value === void 0 ? match : String(value);
  });
};
const K = "catalog.products.create.seoWidget.validation";
function buildSeoBlockMessage(issues, t = englishFallback) {
  if (issues.length <= 3) {
    return t(`${K}.block.list`, "SEO helper: {{issues}}", { issues: issues.join(" ") });
  }
  return t(`${K}.block.summary`, "SEO helper: {{count}} issues found. {{issues}}", {
    count: issues.length,
    issues: issues.slice(0, 2).join(" ")
  });
}
function evaluateProductSeo(data, t = englishFallback) {
  const issues = [];
  const fieldErrors = {};
  const title = data?.title || data?.name;
  if (typeof title === "string" && title.length > 0) {
    if (title.length < 10) {
      issues.push(t(`${K}.issue.titleTooShort`, "Title is too short (min 10 characters)."));
      fieldErrors.title = t(`${K}.fieldError.titleTooShort`, "Title is too short for good SEO (min 10 characters).");
    } else if (title.length > 60) {
      issues.push(t(`${K}.issue.titleTooLong`, "Title is too long (max 60 characters recommended)."));
      fieldErrors.title = t(`${K}.fieldError.titleTooLong`, "Title is too long for optimal SEO (max 60 characters).");
    }
  }
  const description = data?.description;
  if (typeof description === "string") {
    if (description.trim().length === 0) {
      issues.push(t(`${K}.issue.descriptionMissing`, "Add a product description for better SEO."));
      fieldErrors.description = t(`${K}.fieldError.descriptionMissing`, "Provide a description to help search engines understand this product.");
    } else if (description.length < 50) {
      issues.push(t(`${K}.issue.descriptionTooShort`, "Description is too short (min 50 characters)."));
      fieldErrors.description = t(`${K}.fieldError.descriptionTooShort`, "Description is too short for good SEO (min 50 characters).");
    }
  }
  if (issues.length) {
    return { ok: false, issues, fieldErrors, message: buildSeoBlockMessage(issues, t) };
  }
  return { ok: true, issues: [], fieldErrors: {} };
}
export {
  buildSeoBlockMessage,
  evaluateProductSeo
};
//# sourceMappingURL=validation.js.map
