"use client";
import * as React from "react";
import { useT } from "@open-mercato/shared/lib/i18n/context";
function useChannelFieldLabels() {
  const t = useT();
  return React.useMemo(() => ({
    name: t("sales.channels.form.name", "Channel name"),
    code: t("sales.channels.form.code", "Code"),
    description: t("sales.channels.form.description", "Description"),
    websiteUrl: t("sales.channels.form.websiteUrl", "Website URL"),
    contactEmail: t("sales.channels.form.contactEmail", "Contact email"),
    contactPhone: t("sales.channels.form.contactPhone", "Contact phone"),
    statusEntryId: t("sales.channels.form.status", "Status entry ID"),
    addressLine1: t("sales.channels.form.address1", "Address line 1"),
    addressLine2: t("sales.channels.form.address2", "Address line 2"),
    city: t("sales.channels.form.city", "City"),
    region: t("sales.channels.form.region", "State / region"),
    postalCode: t("sales.channels.form.postalCode", "Postal code"),
    country: t("sales.channels.form.country", "Country"),
    latitude: t("sales.channels.form.latitude", "Latitude"),
    longitude: t("sales.channels.form.longitude", "Longitude"),
    isActive: t("sales.channels.form.isActive", "Active")
  }), [t]);
}
function useChannelFields() {
  const t = useT();
  const labels = useChannelFieldLabels();
  const fields = React.useMemo(() => [
    { id: "name", label: labels.name, type: "text", required: true },
    {
      id: "code",
      label: labels.code,
      type: "text",
      description: "Lowercase letters, numbers, and dashes.",
      required: true
    },
    {
      id: "description",
      label: labels.description,
      type: "textarea"
    },
    {
      id: "websiteUrl",
      label: labels.websiteUrl,
      type: "text"
    },
    {
      id: "contactEmail",
      label: labels.contactEmail,
      type: "text"
    },
    {
      id: "contactPhone",
      label: labels.contactPhone,
      type: "text"
    },
    {
      id: "addressLine1",
      label: labels.addressLine1,
      type: "text"
    },
    {
      id: "addressLine2",
      label: labels.addressLine2,
      type: "text"
    },
    {
      id: "city",
      label: labels.city,
      type: "text",
      layout: "half"
    },
    {
      id: "region",
      label: labels.region,
      type: "text",
      layout: "half"
    },
    {
      id: "postalCode",
      label: labels.postalCode,
      type: "text",
      layout: "half"
    },
    {
      id: "country",
      label: labels.country,
      type: "text",
      layout: "half",
      placeholder: "US"
    },
    {
      id: "latitude",
      label: labels.latitude,
      type: "number",
      layout: "half"
    },
    {
      id: "longitude",
      label: labels.longitude,
      type: "number",
      layout: "half"
    },
    {
      id: "isActive",
      label: labels.isActive,
      type: "checkbox"
    }
  ], [labels]);
  const groups = React.useMemo(() => [
    {
      id: "general",
      title: t("sales.channels.form.groups.general", "General"),
      column: 1,
      fields: ["name", "code", "description", "isActive"]
    },
    {
      id: "contact",
      title: t("sales.channels.form.groups.contact", "Contact"),
      column: 1,
      fields: ["websiteUrl", "contactEmail", "contactPhone"]
    },
    {
      id: "address",
      title: t("sales.channels.form.groups.address", "Location"),
      column: 2,
      fields: ["addressLine1", "addressLine2", "city", "region", "postalCode", "country", "latitude", "longitude"]
    }
  ], [t]);
  return { fields, groups };
}
function buildChannelPayload(values) {
  const pick = (value, opts) => {
    if (typeof value !== "string") return void 0;
    const trimmed = value.trim();
    if (!trimmed.length) return void 0;
    return opts?.lowercase ? trimmed.toLowerCase() : trimmed;
  };
  const toNumber = (value) => {
    if (value === null || value === void 0 || value === "") return void 0;
    const num = Number(value);
    return Number.isFinite(num) ? num : void 0;
  };
  return {
    name: pick(values.name) ?? "",
    code: pick(values.code, { lowercase: true }),
    description: pick(values.description),
    websiteUrl: pick(values.websiteUrl),
    contactEmail: pick(values.contactEmail),
    contactPhone: pick(values.contactPhone),
    statusEntryId: pick(values.statusEntryId),
    addressLine1: pick(values.addressLine1),
    addressLine2: pick(values.addressLine2),
    city: pick(values.city),
    region: pick(values.region),
    postalCode: pick(values.postalCode),
    country: pick(values.country),
    latitude: toNumber(values.latitude),
    longitude: toNumber(values.longitude),
    isActive: values.isActive !== false
  };
}
export {
  buildChannelPayload,
  useChannelFields
};
//# sourceMappingURL=channelFormFields.js.map
