import K, { useMemo as s, useRef as Q, useEffect as U, useCallback as C } from "react";
import { flexRender as X } from "@tanstack/react-table";
import Y from "./useCellProperties.js";
import Z from "./useCellStateFlags.js";
import $ from "./useCellEditable.js";
import ee from "./useCellDragAndDrop.js";
import te from "../utils/buildCellClasses.js";
import le from "../utils/calculateCellWidth.js";
import oe from "../../editable-cell/EditableCell.js";
import "../utils/extractCellValue.js";
import "../utils/resolveEditableConfig.js";
function pe(k) {
  const {
    hasColumnSeparator: F,
    cell: V,
    cellsLength: A,
    isSelected: p,
    columnSizingId: H,
    columnSizingDeltaOffset: g,
    handleClickRow: i,
    columnSizeNumber: h,
    record: a,
    rowIndex: N,
    cellEdit: P,
    columns: T
  } = k, { columnId: c, getIndex: _, getCanResize: B, getSize: b, cellRender: d, getContext: R } = Y(V), r = s(() => R(), [R]), m = _(), G = Z({
    columnId: c,
    colIndex: m,
    cellsLength: A,
    hasColumnSeparator: F,
    columnSizingId: H,
    getCanResize: B
  }), { isSelectionColumn: l, isActionColumn: o, isResizing: n, canResize: L, isBorderVisible: S } = G, { editableConfig: e, isCellEditable: u, cellValue: z, rawCellValue: x, dataIndex: E, handleCellSave: I } = $({
    cellEdit: P,
    columns: T,
    columnId: c,
    record: a,
    rowIndex: N,
    isSelectionColumn: l,
    isActionColumn: o
  }), { isDragging: f, setNodeRef: M, transformStyle: w } = ee(c), y = Q(!1);
  U(() => {
    y.current = n;
  }, [n]);
  const O = s(
    () => te({
      isBorderVisible: S,
      isSelectionColumn: l,
      isSelected: p,
      isActionColumn: o
    }),
    [S, l, p, o]
  ), D = s(
    () => le({
      isSelectionColumn: l,
      isActionColumn: o,
      isResizing: n,
      getSize: b,
      columnSizingDeltaOffset: g,
      columnSizeNumber: h
    }),
    [l, o, n, b, g, h]
  ), W = C(() => {
    !y.current && i && i();
  }, [i]), j = C(
    (t) => {
      t.preventDefault(), t.stopPropagation(), r.table.getHeaderGroups()[0].headers[m].getResizeHandler()(t);
    },
    [r.table, m]
  ), q = C(() => {
    const t = d ? X(d, r) : null;
    if (u && e) {
      const v = e.type === "custom" ? x : z;
      return K.createElement(oe, {
        value: v,
        isEditable: u,
        editorType: e.type,
        dateFormat: e.dateFormat,
        record: a,
        dataIndex: E,
        renderEditor: e.renderEditor,
        onSave: I,
        children: t
      });
    }
    return t;
  }, [d, r, u, e, z, x, E, I, a]), J = s(
    () => ({
      transform: w,
      opacity: f ? 0.8 : 1,
      position: "relative",
      transition: "width transform 0.2s ease-in-out",
      zIndex: f ? 1 : 0,
      width: D,
      flexShrink: 0
    }),
    [w, f, D]
  );
  return {
    cellClasses: O,
    newStyle: J,
    canResize: L,
    isResizing: n,
    handleClick: W,
    handleResize: j,
    renderCellContent: q,
    setNodeRef: M
  };
}
export {
  pe as default
};
//# sourceMappingURL=useDataTableCell.js.map
