"use client";
import { jsxs as r, jsx as b } from "react/jsx-runtime";
import { useDataCrossTable as $ } from "./data-cross-table-context.js";
import { Button as c } from "../../button.js";
import { Icon as g } from "../../icon.js";
const B = ({ className: x = "" }) => {
  const {
    editedCells: f,
    setEditedCells: m,
    toDefaultCells: n,
    setToDefaultCells: d,
    editMode: p,
    setEditMode: u,
    onConfirmedCells: o,
    editConfirmLabel: D,
    editCancelLabel: j,
    editRestoreDefaultLabel: k,
    showDefaultActionButton: C
  } = $();
  if (!p) return null;
  const l = Object.keys(f).length, s = Object.keys(n).length, i = l > 0 || s > 0, L = () => {
    if (o) {
      const a = Object.entries(n).map(
        ([, { value: I, cell: e }]) => ({
          fromId: e.fromId,
          toId: e.toId,
          id: e.id,
          value: I
        })
      );
      o({
        editedCells: [],
        toDefaultCells: a
      });
    }
    d({});
  }, N = () => {
    if (o && i) {
      const a = Object.entries(f).map(
        ([, { value: e, cell: t }]) => ({
          fromId: t.fromId,
          toId: t.toId,
          id: t.id,
          value: e
        })
      ), h = Object.entries(n).map(
        ([, { value: e, cell: t }]) => ({
          fromId: t.fromId,
          toId: t.toId,
          id: t.id,
          value: e
        })
      );
      o({
        editedCells: a,
        toDefaultCells: h
      });
    }
    m({}), d({}), u(!1);
  }, O = () => {
    m({}), d({}), u(!1);
  };
  return /* @__PURE__ */ r("div", { className: `flex items-center space-x-2 ${x}`, children: [
    C && /* @__PURE__ */ r(
      c,
      {
        variant: "outline",
        size: "sm",
        onClick: L,
        disabled: s === 0,
        className: "text-xs",
        iconLeft: "RotateCcw",
        children: [
          k,
          " ",
          s > 0 && `(${s})`
        ]
      }
    ),
    /* @__PURE__ */ b(
      c,
      {
        variant: "outline",
        size: "sm",
        onClick: O,
        className: "text-xs",
        iconLeft: "X",
        children: j
      }
    ),
    /* @__PURE__ */ r(
      c,
      {
        size: "sm",
        onClick: N,
        disabled: !i,
        className: "text-xs",
        children: [
          /* @__PURE__ */ b(g, { name: "Check", className: "mr-1 h-3 w-3" }),
          D,
          " ",
          C ? i && `(${l + s})` : l > 0 && `(${l})`
        ]
      }
    )
  ] });
};
export {
  B as DataCrossTableButtonsGroup
};
