"use client";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
import { Button } from "@open-mercato/ui/primitives/button";
import { Spinner } from "@open-mercato/ui/primitives/spinner";
import { Card, CardContent, CardHeader, CardTitle } from "@open-mercato/ui/primitives/card";
import { Badge } from "@open-mercato/ui/primitives/badge";
import { ErrorMessage } from "@open-mercato/ui/backend/detail";
import { useT } from "@open-mercato/shared/lib/i18n/context";
import { Package, CheckCircle2 } from "lucide-react";
const formatAddress = (addr) => [addr.line1, addr.city, addr.postalCode, addr.countryCode].filter(Boolean).join(", ");
const ConfirmStep = (props) => {
  const {
    rates,
    ratesError,
    selectedRate,
    selectedProvider,
    origin,
    destination,
    packages,
    labelFormat,
    senderContact,
    receiverContact,
    targetPoint,
    c2cSendingMethod,
    isSubmitting,
    onRateSelect,
    onBack,
    onSubmit
  } = props;
  const t = useT();
  return /* @__PURE__ */ jsxs("section", { className: "space-y-6", children: [
    ratesError ? /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
      /* @__PURE__ */ jsx(ErrorMessage, { label: ratesError }),
      /* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", size: "sm", onClick: onBack, children: t("shipping_carriers.create.action.editConfiguration", "Edit configuration") })
    ] }) : null,
    rates.length === 0 && !ratesError ? /* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsx(CardContent, { className: "py-8 text-center text-sm text-muted-foreground", children: t("shipping_carriers.create.noRates", "No rates available for this route and package configuration.") }) }) : /* @__PURE__ */ jsxs(Card, { children: [
      /* @__PURE__ */ jsx(CardHeader, { children: /* @__PURE__ */ jsx(CardTitle, { className: "text-base", children: t("shipping_carriers.create.section.selectRate", "Select service") }) }),
      /* @__PURE__ */ jsx(CardContent, { children: /* @__PURE__ */ jsx("div", { className: "space-y-2", children: rates.map((rate) => {
        const isSelected = selectedRate?.serviceCode === rate.serviceCode;
        return /* @__PURE__ */ jsxs(
          "button",
          {
            type: "button",
            className: `flex w-full cursor-pointer items-center justify-between rounded-lg border p-3 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring ${isSelected ? "border-primary bg-primary/5" : "hover:bg-muted/50"}`,
            onClick: () => onRateSelect(rate),
            children: [
              /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
                /* @__PURE__ */ jsx(Package, { className: "h-4 w-4 shrink-0 text-muted-foreground" }),
                /* @__PURE__ */ jsxs("div", { children: [
                  /* @__PURE__ */ jsx("p", { className: "font-medium", children: rate.serviceName }),
                  /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: rate.serviceCode })
                ] })
              ] }),
              /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
                rate.estimatedDays !== void 0 ? /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: t("shipping_carriers.create.estimatedDays", "{days} day(s)", { days: rate.estimatedDays }) }) : null,
                /* @__PURE__ */ jsxs(Badge, { variant: "secondary", children: [
                  rate.amount.toFixed(2),
                  " ",
                  rate.currencyCode
                ] }),
                isSelected ? /* @__PURE__ */ jsx(CheckCircle2, { className: "h-4 w-4 text-primary" }) : null
              ] })
            ]
          },
          rate.serviceCode
        );
      }) }) })
    ] }),
    /* @__PURE__ */ jsxs(Card, { children: [
      /* @__PURE__ */ jsx(CardHeader, { children: /* @__PURE__ */ jsx(CardTitle, { className: "text-base", children: t("shipping_carriers.create.section.summary", "Summary") }) }),
      /* @__PURE__ */ jsx(CardContent, { children: /* @__PURE__ */ jsxs("dl", { className: "grid gap-2 text-sm sm:grid-cols-2", children: [
        /* @__PURE__ */ jsxs("div", { children: [
          /* @__PURE__ */ jsx("dt", { className: "text-xs font-medium uppercase tracking-wide text-muted-foreground", children: t("shipping_carriers.create.summary.carrier", "Carrier") }),
          /* @__PURE__ */ jsx("dd", { className: "mt-0.5 capitalize", children: selectedProvider.replace(/_/g, " ") })
        ] }),
        selectedRate ? /* @__PURE__ */ jsxs("div", { children: [
          /* @__PURE__ */ jsx("dt", { className: "text-xs font-medium uppercase tracking-wide text-muted-foreground", children: t("shipping_carriers.create.summary.service", "Service") }),
          /* @__PURE__ */ jsx("dd", { className: "mt-0.5", children: selectedRate.serviceName })
        ] }) : null,
        /* @__PURE__ */ jsxs("div", { children: [
          /* @__PURE__ */ jsx("dt", { className: "text-xs font-medium uppercase tracking-wide text-muted-foreground", children: t("shipping_carriers.create.summary.from", "From") }),
          /* @__PURE__ */ jsx("dd", { className: "mt-0.5", children: formatAddress(origin) })
        ] }),
        /* @__PURE__ */ jsxs("div", { children: [
          /* @__PURE__ */ jsx("dt", { className: "text-xs font-medium uppercase tracking-wide text-muted-foreground", children: t("shipping_carriers.create.summary.to", "To") }),
          /* @__PURE__ */ jsx("dd", { className: "mt-0.5", children: formatAddress(destination) })
        ] }),
        /* @__PURE__ */ jsxs("div", { children: [
          /* @__PURE__ */ jsx("dt", { className: "text-xs font-medium uppercase tracking-wide text-muted-foreground", children: t("shipping_carriers.create.summary.packages", "Packages") }),
          /* @__PURE__ */ jsx("dd", { className: "mt-0.5", children: packages.length })
        ] }),
        /* @__PURE__ */ jsxs("div", { children: [
          /* @__PURE__ */ jsx("dt", { className: "text-xs font-medium uppercase tracking-wide text-muted-foreground", children: t("shipping_carriers.create.summary.labelFormat", "Label format") }),
          /* @__PURE__ */ jsx("dd", { className: "mt-0.5 uppercase", children: labelFormat })
        ] }),
        senderContact.phone || senderContact.email ? /* @__PURE__ */ jsxs("div", { children: [
          /* @__PURE__ */ jsx("dt", { className: "text-xs font-medium uppercase tracking-wide text-muted-foreground", children: t("shipping_carriers.create.summary.senderContact", "Sender contact") }),
          /* @__PURE__ */ jsx("dd", { className: "mt-0.5", children: [senderContact.phone, senderContact.email].filter(Boolean).join(" / ") })
        ] }) : null,
        receiverContact.phone || receiverContact.email ? /* @__PURE__ */ jsxs("div", { children: [
          /* @__PURE__ */ jsx("dt", { className: "text-xs font-medium uppercase tracking-wide text-muted-foreground", children: t("shipping_carriers.create.summary.receiverContact", "Receiver contact") }),
          /* @__PURE__ */ jsx("dd", { className: "mt-0.5", children: [receiverContact.phone, receiverContact.email].filter(Boolean).join(" / ") })
        ] }) : null,
        targetPoint ? /* @__PURE__ */ jsxs("div", { children: [
          /* @__PURE__ */ jsx("dt", { className: "text-xs font-medium uppercase tracking-wide text-muted-foreground", children: t("shipping_carriers.create.summary.targetPoint", "Locker point") }),
          /* @__PURE__ */ jsx("dd", { className: "mt-0.5", children: targetPoint })
        ] }) : null,
        c2cSendingMethod ? /* @__PURE__ */ jsxs("div", { children: [
          /* @__PURE__ */ jsx("dt", { className: "text-xs font-medium uppercase tracking-wide text-muted-foreground", children: t("shipping_carriers.create.summary.c2cSendingMethod", "C2C sending method") }),
          /* @__PURE__ */ jsx("dd", { className: "mt-0.5", children: c2cSendingMethod })
        ] }) : null
      ] }) })
    ] }),
    /* @__PURE__ */ jsxs("div", { className: "flex justify-between gap-3", children: [
      /* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", onClick: onBack, disabled: isSubmitting, children: t("shipping_carriers.create.back", "Back") }),
      /* @__PURE__ */ jsx(
        Button,
        {
          type: "button",
          onClick: onSubmit,
          disabled: !selectedRate || isSubmitting,
          children: isSubmitting ? /* @__PURE__ */ jsxs(Fragment, { children: [
            /* @__PURE__ */ jsx(Spinner, { className: "mr-2 h-4 w-4" }),
            t("shipping_carriers.create.submitting", "Creating shipment...")
          ] }) : t("shipping_carriers.create.submit", "Create shipment")
        }
      )
    ] })
  ] });
};
export {
  ConfirmStep
};
//# sourceMappingURL=ConfirmStep.js.map
