import {
  InventoryItemGeneralSection
} from "./chunk-LFKTHNWI.js";
import {
  SectionRow
} from "./chunk-3XPXUIK3.js";
import {
  TwoColumnPage
} from "./chunk-V5J73NPW.js";
import {
  TwoColumnPageSkeleton
} from "./chunk-INNFZYX2.js";
import {
  ActionMenu
} from "./chunk-BDGZ4EQO.js";
import {
  useReservationItem
} from "./chunk-22XJUSMM.js";
import {
  useStockLocation
} from "./chunk-OFKUNYQJ.js";
import {
  useInventoryItem
} from "./chunk-BA2HXHTW.js";

// src/pages/reservations/reservation-detail/reservation-detail.tsx
import { Children } from "react";
import { useLoaderData, useParams } from "react-router-dom";

// src/pages/reservations/reservation-detail/components/reservation-general-section/reservation-general-section.tsx
import { Container, Heading } from "@medusajs/ui";
import { PencilSquare } from "@medusajs/icons";
import { useTranslation } from "react-i18next";
import { jsx, jsxs } from "react/jsx-runtime";
var ReservationGeneralSection = ({
  reservation
}) => {
  const { t } = useTranslation();
  const { inventory_item: inventoryItem, isPending: isLoadingInventoryItem } = useInventoryItem(reservation.inventory_item_id);
  const { stock_location: location, isPending: isLoadingLocation } = useStockLocation(reservation.location_id);
  if (isLoadingInventoryItem || !inventoryItem || isLoadingLocation || !location) {
    return /* @__PURE__ */ jsx("div", { children: "Loading..." });
  }
  const locationLevel = inventoryItem.location_levels.find(
    (level) => level.location_id === reservation.location_id
  );
  return /* @__PURE__ */ jsxs(Container, { className: "divide-y p-0", children: [
    /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-6 py-4", children: [
      /* @__PURE__ */ jsx(Heading, { children: t("inventory.reservation.header", {
        itemName: inventoryItem.title ?? inventoryItem.sku
      }) }),
      /* @__PURE__ */ jsx(
        ActionMenu,
        {
          groups: [
            {
              actions: [
                {
                  icon: /* @__PURE__ */ jsx(PencilSquare, {}),
                  label: t("actions.edit"),
                  to: `edit`
                }
              ]
            }
          ]
        }
      )
    ] }),
    /* @__PURE__ */ jsx(
      SectionRow,
      {
        title: t("inventory.reservation.lineItemId"),
        value: reservation.line_item_id
      }
    ),
    /* @__PURE__ */ jsx(
      SectionRow,
      {
        title: t("inventory.reservation.description"),
        value: reservation.description
      }
    ),
    /* @__PURE__ */ jsx(
      SectionRow,
      {
        title: t("inventory.reservation.location"),
        value: location?.name
      }
    ),
    /* @__PURE__ */ jsx(
      SectionRow,
      {
        title: t("inventory.reservation.inStockAtLocation"),
        value: locationLevel?.stocked_quantity
      }
    ),
    /* @__PURE__ */ jsx(
      SectionRow,
      {
        title: t("inventory.reservation.availableAtLocation"),
        value: locationLevel?.available_quantity
      }
    ),
    /* @__PURE__ */ jsx(
      SectionRow,
      {
        title: t("inventory.reservation.reservedAtLocation"),
        value: locationLevel?.reserved_quantity
      }
    )
  ] });
};

// src/pages/reservations/reservation-detail/reservation-detail.tsx
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
var Root = ({ children }) => {
  const { id } = useParams();
  const initialData = useLoaderData();
  const { reservation, isLoading, isError, error } = useReservationItem(
    id,
    void 0,
    {
      initialData
    }
  );
  const { inventory_item } = useInventoryItem(
    reservation?.inventory_item?.id,
    void 0,
    { enabled: !!reservation?.inventory_item?.id }
  );
  if (isLoading || !reservation) {
    return /* @__PURE__ */ jsx2(
      TwoColumnPageSkeleton,
      {
        mainSections: 1,
        sidebarSections: 1,
        showJSON: true,
        showMetadata: true
      }
    );
  }
  if (isError) {
    throw error;
  }
  return Children.count(children) > 0 ? /* @__PURE__ */ jsx2(TwoColumnPage, { data: reservation, showJSON: true, showMetadata: true, "data-testid": "reservation-detail-page", children }) : /* @__PURE__ */ jsxs2(TwoColumnPage, { data: reservation, showJSON: true, showMetadata: true, "data-testid": "reservation-detail-page", children: [
    /* @__PURE__ */ jsx2(TwoColumnPage.Main, { children: /* @__PURE__ */ jsx2(ReservationGeneralSection, { reservation }) }),
    /* @__PURE__ */ jsx2(TwoColumnPage.Sidebar, { children: inventory_item && /* @__PURE__ */ jsx2(InventoryItemGeneralSection, { inventoryItem: inventory_item }) })
  ] });
};
var ReservationDetailPage = Object.assign(Root, {
  Main: TwoColumnPage.Main,
  Sidebar: TwoColumnPage.Sidebar,
  MainGeneralSection: ReservationGeneralSection,
  SidebarInventorySection: InventoryItemGeneralSection
});

export {
  ReservationDetailPage
};
