import {
  Collapse
} from "./chunk-NFDQJVFA.js";
import {
  __spreadValues
} from "./chunk-CRTRMMJ7.js";

// src/molecules/expand-table/row.tsx
import {
  flexRender
} from "@tanstack/react-table";
import { useCallback, useMemo, useState } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
function Row(props) {
  const { row, ExpandComp, gridTemplateColumns, getRowStyle, getCellStyle } = props;
  const [open, setOpen] = useState(false);
  const onClickRow = useCallback(() => {
    var _a;
    (_a = props.onRowClick) == null ? void 0 : _a.call(props, row.original);
    setOpen((prev) => !prev);
  }, [props, row.original]);
  const rowClassName = useMemo(() => {
    const baseCls = ["tr-wrapper"];
    if (ExpandComp) {
      baseCls.push("expandable");
    }
    if (props.onRowClick) {
      baseCls.push("clickable");
    }
    return baseCls.join(" ");
  }, [ExpandComp, props.onRowClick]);
  return /* @__PURE__ */ jsxs("div", { className: rowClassName, children: [
    /* @__PURE__ */ 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__ */ 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: [
                flexRender(cell.column.columnDef.cell, cell.getContext()),
                ((_c = cell.column.columnDef.meta) == null ? void 0 : _c.OpenBtn) ? /* @__PURE__ */ jsx(
                  cell.column.columnDef.meta.OpenBtn,
                  {
                    data: row.original,
                    open,
                    setIsOpen: setOpen
                  }
                ) : null
              ]
            },
            cell.id
          );
        })
      },
      `tr_${row.id}`
    ),
    ExpandComp ? /* @__PURE__ */ jsx(Collapse, { open, children: /* @__PURE__ */ jsx("div", { className: "expand-comp-wrapper", children: /* @__PURE__ */ jsx(ExpandComp, { row }) }) }) : null
  ] }, `tr-wrapper_${row.id}`);
}

export {
  Row
};
//# sourceMappingURL=chunk-2SB6B77U.js.map