"use client";
import { CUSTOMER_INTERACTION_TASK_SOURCE, CUSTOMER_INTERACTION_TASK_TYPE } from "../../lib/interactionCompatibility.js";
function formatDate(value) {
  if (!value) return null;
  const date = new Date(value);
  if (Number.isNaN(date.getTime())) return null;
  return date.toLocaleDateString();
}
function formatTemplate(template, params) {
  if (!template) return template;
  if (!params) return template;
  return template.replace(/\{\{(\w+)\}\}|\{(\w+)\}/g, (match, doubleKey, singleKey) => {
    const key = doubleKey ?? singleKey;
    if (!key) return match;
    const value = params[key];
    return value === void 0 ? match : String(value);
  });
}
function toLocalDateTimeInput(value) {
  if (!value) return "";
  const date = new Date(value);
  if (Number.isNaN(date.getTime())) return "";
  const pad = (input) => `${input}`.padStart(2, "0");
  return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(
    date.getMinutes()
  )}`;
}
function resolveTodoHref(source, todoId) {
  if (!todoId) return null;
  if (!source) return null;
  if (source === CUSTOMER_INTERACTION_TASK_SOURCE || source === CUSTOMER_INTERACTION_TASK_TYPE) return null;
  const [module] = source.split(":");
  if (!module) return null;
  if (module === "example") {
    return `/backend/todos/${encodeURIComponent(todoId)}/edit`;
  }
  return `/backend/${module}/todos/${encodeURIComponent(todoId)}/edit`;
}
function resolveTodoApiPath(source) {
  if (!source) return null;
  if (source === CUSTOMER_INTERACTION_TASK_SOURCE || source === CUSTOMER_INTERACTION_TASK_TYPE) {
    return "/api/customers/todos";
  }
  const [module] = source.split(":");
  if (!module) return null;
  return `/api/${module}/todos`;
}
function createDictionarySelectLabels(kind, translate) {
  const base = {
    valueLabel: translate("customers.people.form.dictionary.valueLabel", "Name"),
    valuePlaceholder: translate("customers.people.form.dictionary.valuePlaceholder", "Name"),
    labelLabel: translate("customers.people.form.dictionary.labelLabel", "Label"),
    labelPlaceholder: translate("customers.people.form.dictionary.labelPlaceholder", "Display name shown in UI"),
    emptyError: translate("customers.people.form.dictionary.errorRequired", "Please enter a name"),
    cancelLabel: translate("customers.people.form.dictionary.cancel", "Cancel"),
    saveLabel: translate("customers.people.form.dictionary.save", "Save"),
    saveShortcutHint: translate("customers.people.form.dictionary.saveShortcut", "\u2318/Ctrl + Enter"),
    errorLoad: translate("customers.people.form.dictionary.errorLoad", "Failed to load options"),
    errorSave: translate("customers.people.form.dictionary.error", "Failed to save option"),
    loadingLabel: translate("customers.people.form.dictionary.loading", "Loading\u2026"),
    manageTitle: translate("customers.people.form.dictionary.manage", "Manage dictionary"),
    placeholder: translate("customers.people.form.dictionary.placeholder", "Select an option"),
    addLabel: translate("customers.people.form.dictionary.add", "Add option"),
    addPrompt: translate("customers.people.form.dictionary.prompt", "Name your option"),
    dialogTitle: translate("customers.people.form.dictionary.dialogTitle", "Add option")
  };
  switch (kind) {
    case "statuses":
      return {
        ...base,
        placeholder: translate("customers.people.form.status.placeholder", "Select a status"),
        addLabel: translate("customers.people.form.dictionary.addStatus", "Add status"),
        addPrompt: translate("customers.people.form.dictionary.promptStatus", "Name the status"),
        dialogTitle: translate("customers.people.form.dictionary.dialogTitleStatus", "Add status")
      };
    case "lifecycle-stages":
      return {
        ...base,
        placeholder: translate("customers.people.form.lifecycleStage.placeholder", "Select a lifecycle stage"),
        addLabel: translate("customers.people.form.dictionary.addLifecycleStage", "Add lifecycle stage"),
        addPrompt: translate("customers.people.form.dictionary.promptLifecycleStage", "Name the lifecycle stage"),
        dialogTitle: translate("customers.people.form.dictionary.dialogTitleLifecycleStage", "Add lifecycle stage")
      };
    case "sources":
      return {
        ...base,
        placeholder: translate("customers.people.form.source.placeholder", "Select a source"),
        addLabel: translate("customers.people.form.dictionary.addSource", "Add source"),
        addPrompt: translate("customers.people.form.dictionary.promptSource", "Name the source"),
        dialogTitle: translate("customers.people.form.dictionary.dialogTitleSource", "Add source")
      };
    case "activity-types":
      return {
        ...base,
        placeholder: translate("customers.people.form.activityType.placeholder", "Select an activity type"),
        addLabel: translate("customers.people.form.dictionary.addActivityType", "Add activity type"),
        addPrompt: translate("customers.people.form.dictionary.promptActivityType", "Name the activity type"),
        dialogTitle: translate("customers.people.form.dictionary.dialogTitleActivityType", "Add activity type")
      };
    case "deal-statuses":
      return {
        ...base,
        placeholder: translate("customers.deals.form.status.placeholder", "Select a deal status"),
        addLabel: translate("customers.deals.form.dictionary.addStatus", "Add deal status"),
        addPrompt: translate("customers.deals.form.dictionary.promptStatus", "Name the deal status"),
        dialogTitle: translate("customers.deals.form.dictionary.dialogTitleStatus", "Add deal status")
      };
    case "pipeline-stages":
      return {
        ...base,
        placeholder: translate("customers.deals.form.pipeline.placeholder", "Select a pipeline stage"),
        addLabel: translate("customers.deals.form.dictionary.addPipelineStage", "Add pipeline stage"),
        addPrompt: translate("customers.deals.form.dictionary.promptPipelineStage", "Name the pipeline stage"),
        dialogTitle: translate("customers.deals.form.dictionary.dialogTitlePipelineStage", "Add pipeline stage")
      };
    case "job-titles":
      return {
        ...base,
        placeholder: translate("customers.people.form.jobTitle.placeholder", "Select a job title"),
        addLabel: translate("customers.people.form.dictionary.addJobTitle", "Add job title"),
        addPrompt: translate("customers.people.form.dictionary.promptJobTitle", "Name the job title"),
        dialogTitle: translate("customers.people.form.dictionary.dialogTitleJobTitle", "Add job title")
      };
    case "address-types":
      return {
        ...base,
        placeholder: translate("customers.people.form.addressType.placeholder", "Select an address type"),
        addLabel: translate("customers.people.form.dictionary.addAddressType", "Add address type"),
        addPrompt: translate("customers.people.form.dictionary.promptAddressType", "Name the address type"),
        dialogTitle: translate("customers.people.form.dictionary.dialogTitleAddressType", "Add address type")
      };
    default:
      return base;
  }
}
function formatCurrency(amount, currency) {
  try {
    return new Intl.NumberFormat(void 0, {
      style: "currency",
      currency: currency || "PLN",
      maximumFractionDigits: 0
    }).format(amount);
  } catch {
    return `${amount.toLocaleString()} ${currency || "PLN"}`;
  }
}
function formatFallbackLabel(value) {
  return value.replace(/[_-]+/g, " ").replace(/^\w/, (c) => c.toUpperCase());
}
export {
  createDictionarySelectLabels,
  formatCurrency,
  formatDate,
  formatFallbackLabel,
  formatTemplate,
  resolveTodoApiPath,
  resolveTodoHref,
  toLocalDateTimeInput
};
//# sourceMappingURL=utils.js.map
