"use client";
import { jsx } from "react/jsx-runtime";
import * as React from "react";
import { useRouter } from "next/navigation";
import { Page, PageBody } from "@open-mercato/ui/backend/Page";
import { CrudForm } from "@open-mercato/ui/backend/CrudForm";
import { createCrud } from "@open-mercato/ui/backend/utils/crud";
import { flash } from "@open-mercato/ui/backend/FlashMessages";
import { useT } from "@open-mercato/shared/lib/i18n/context";
import { useOrganizationScopeDetail } from "@open-mercato/shared/lib/frontend/useOrganizationScope";
import { apiCall } from "@open-mercato/ui/backend/utils/apiCall";
import {
  loadCurrencyOptions,
  exchangeRateGroups,
  validateExchangeRateForm,
  buildExchangeRatePayload
} from "../../../lib/exchangeRateFormConfig.js";
function CreateExchangeRatePage() {
  const t = useT();
  const router = useRouter();
  const { organizationId, tenantId } = useOrganizationScopeDetail();
  const loadOptions = React.useCallback(
    (query) => loadCurrencyOptions(apiCall, query),
    []
  );
  const groups = React.useMemo(
    () => exchangeRateGroups(t, loadOptions),
    [t, loadOptions]
  );
  return /* @__PURE__ */ jsx(Page, { children: /* @__PURE__ */ jsx(PageBody, { children: /* @__PURE__ */ jsx(
    CrudForm,
    {
      title: t("exchangeRates.create.title"),
      backHref: "/backend/exchange-rates",
      fields: [],
      groups,
      submitLabel: t("exchangeRates.form.action.create"),
      cancelHref: "/backend/exchange-rates",
      onSubmit: async (values) => {
        const validated = validateExchangeRateForm(values, t);
        const payload = {
          organizationId,
          tenantId,
          ...buildExchangeRatePayload(values, validated)
        };
        await createCrud("currencies/exchange-rates", payload);
        flash(t("exchangeRates.flash.created"), "success");
        router.push("/backend/exchange-rates");
      }
    }
  ) }) });
}
export {
  CreateExchangeRatePage as default
};
//# sourceMappingURL=page.js.map
