"use strict";
var import_List = require("../List.css");
const jsxRuntime = require("react/jsx-runtime");
const kit_Button = require("./Button.cjs");
const kit_Column = require("./Column.cjs");
const kit_Dropdown = require("./Dropdown.cjs");
const kit_Icon = require("./Icon.cjs");
const kit_internal_Elevation = require("./internal/Elevation.cjs");
const kit_Row = require("./Row.cjs");
const kit_Typography = require("../Typography-g8d4JFSj.cjs");
const item = "List_item_7964b";
const compact = "List_compact_7964b";
const icon = "List_icon_7964b";
const actions = "List_actions_7964b";
const clickable = "List_clickable_7964b";
const css = {
  item,
  compact,
  icon,
  actions,
  clickable
};
const getMenuOptions = (menu) => {
  return menu == null ? void 0 : menu.map((m, idx) => {
    return {
      key: idx,
      label: m.name
    };
  });
};
const List = ({ items, compact: compact2 }) => {
  return /* @__PURE__ */ jsxRuntime.jsx("div", { children: items.map((row, idx) => {
    var _a, _b;
    const rowClasses = [css.item];
    if (row.onClick)
      rowClasses.push(css.clickable);
    if (compact2)
      rowClasses.push(css.compact);
    return /* @__PURE__ */ jsxRuntime.jsxs(
      kit_internal_Elevation.ElevationWrapper,
      {
        border: true,
        className: rowClasses.join(" "),
        hover: true,
        tabIndex: 0,
        onClick: row.onClick,
        children: [
          /* @__PURE__ */ jsxRuntime.jsxs(kit_Row.Row, { height: row.subtitle ? 52 : 40, children: [
            /* @__PURE__ */ jsxRuntime.jsx(kit_Column, { width: "hug", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: css.icon, children: /* @__PURE__ */ jsxRuntime.jsx(kit_Icon.default, { decorative: true, name: row.icon, size: "small" }) }) }),
            /* @__PURE__ */ jsxRuntime.jsxs(kit_Row.Row, { width: "fill", children: [
              /* @__PURE__ */ jsxRuntime.jsxs(kit_Column, { gap: 0, width: "fill", children: [
                /* @__PURE__ */ jsxRuntime.jsx(kit_Typography.Title, { size: "x-small", children: row.title }),
                !compact2 && row.subtitle && /* @__PURE__ */ jsxRuntime.jsx(kit_Typography.Label, { inactive: true, size: "small", children: row.subtitle })
              ] }),
              !compact2 && ((_a = row.columns) == null ? void 0 : _a.map((col, idx2) => {
                return /* @__PURE__ */ jsxRuntime.jsx(kit_Column, { width: "fill", children: col }, idx2);
              }))
            ] })
          ] }),
          (row.buttons && row.buttons.length > 0 || row.menu && row.menu.length > 0) && /* @__PURE__ */ jsxRuntime.jsx(
            "div",
            {
              className: css.actions,
              onClick: (e) => {
                e.stopPropagation();
              },
              children: /* @__PURE__ */ jsxRuntime.jsxs(kit_Row.Row, { children: [
                (_b = row.buttons) == null ? void 0 : _b.map((b, idx2) => {
                  return /* @__PURE__ */ jsxRuntime.jsx(kit_Button, { onClick: b.onClick, children: b.name }, idx2);
                }),
                row.menu && row.menu.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(
                  kit_Dropdown,
                  {
                    menu: getMenuOptions(row.menu),
                    onClick: (key) => {
                      var _a2;
                      const opt = row.menu ? row.menu[parseInt(key)] : void 0;
                      (_a2 = opt == null ? void 0 : opt.onClick) == null ? void 0 : _a2.call(opt);
                    },
                    children: /* @__PURE__ */ jsxRuntime.jsx(
                      kit_Button,
                      {
                        icon: /* @__PURE__ */ jsxRuntime.jsx(kit_Icon.default, { name: "overflow-vertical", title: "Action menu" }),
                        type: "text"
                      }
                    )
                  }
                )
              ] })
            }
          )
        ]
      },
      idx
    );
  }) });
};
module.exports = List;
