"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/molecules/expand-table/row.tsx
var row_exports = {};
__export(row_exports, {
  Row: () => Row
});
module.exports = __toCommonJS(row_exports);
var import_react_table = require("@tanstack/react-table");
var import_react2 = require("react");

// src/atoms/collapse.tsx
var import_react = require("react");
var import_jsx_runtime = require("react/jsx-runtime");
function Collapse(props) {
  const { children, closedHeight = "0" } = props;
  const [open, setOpen] = (0, import_react.useState)(() => {
    return props.open || props.defaultOpen || false;
  });
  (0, import_react.useEffect)(() => {
    if (props.open === void 0) return;
    setOpen(props.open);
  }, [props.open]);
  const ref = (0, import_react.useRef)(null);
  (0, import_react.useEffect)(() => {
    if (!ref.current) return;
    ref.current.style.maxHeight = open ? `${ref.current.scrollHeight}px` : closedHeight;
  }, [closedHeight, open]);
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "tipp-collapse", ref, children });
}

// src/molecules/expand-table/row.tsx
var import_jsx_runtime2 = require("react/jsx-runtime");
function Row(props) {
  const { row, ExpandComp, gridTemplateColumns, getRowStyle, getCellStyle } = props;
  const [open, setOpen] = (0, import_react2.useState)(false);
  const onClickRow = (0, import_react2.useCallback)(() => {
    var _a;
    (_a = props.onRowClick) == null ? void 0 : _a.call(props, row.original);
    setOpen((prev) => !prev);
  }, [props, row.original]);
  const rowClassName = (0, import_react2.useMemo)(() => {
    const baseCls = ["tr-wrapper"];
    if (ExpandComp) {
      baseCls.push("expandable");
    }
    if (props.onRowClick) {
      baseCls.push("clickable");
    }
    return baseCls.join(" ");
  }, [ExpandComp, props.onRowClick]);
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: rowClassName, children: [
    /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
      "button",
      {
        className: "tr",
        onClick: onClickRow,
        style: __spreadValues({
          gridTemplateColumns
        }, (getRowStyle == null ? void 0 : getRowStyle(row.original)) || {}),
        type: "button",
        children: row.getVisibleCells().map((cell) => {
          var _a, _b, _c;
          const autoSize = (_a = cell.column.columnDef.meta) == null ? void 0 : _a.autoSize;
          const justifyContent = ((_b = cell.column.columnDef.meta) == null ? void 0 : _b.align) || props.defaultAlign;
          return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
            "div",
            {
              className: "td",
              style: __spreadValues({
                // width: autoSize ? undefined : cell.column.getSize(),
                flexGrow: autoSize ? 1 : void 0,
                justifyContent
              }, (getCellStyle == null ? void 0 : getCellStyle(row.original)) || {}),
              children: [
                (0, import_react_table.flexRender)(cell.column.columnDef.cell, cell.getContext()),
                ((_c = cell.column.columnDef.meta) == null ? void 0 : _c.OpenBtn) ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
                  cell.column.columnDef.meta.OpenBtn,
                  {
                    data: row.original,
                    open,
                    setIsOpen: setOpen
                  }
                ) : null
              ]
            },
            cell.id
          );
        })
      },
      `tr_${row.id}`
    ),
    ExpandComp ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Collapse, { open, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "expand-comp-wrapper", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ExpandComp, { row }) }) }) : null
  ] }, `tr-wrapper_${row.id}`);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  Row
});
//# sourceMappingURL=row.cjs.map