import { jsx as t, jsxs as b } from "@emotion/react/jsx-runtime";
import { useState as D } from "react";
import { ContainerLabelValueColumnStyled as L, ContentWrapperColumnStyled as R, LabelHeaderColumnStyled as z, EditorCellWrapperStyled as I, ValueColumnStyled as y, EditablePlaceholderStyled as T, IconButtonEditStyled as A } from "../../../../slots/DataGridSlot.js";
import { DICTIONARY as O } from "../../../../dictionary.js";
import { useModuleDictionary as V } from "@m4l/core";
import { ActionsEditOutlined as j } from "@m4l/icons";
import { useComponentSize as H } from "../../../../../../hooks/useComponentSize/index.js";
import { useDataGrid as K } from "../../../../hooks/shared/useDataGrid/useDataGrid.js";
function Q({
  row: r,
  rows: c,
  rowIndex: n,
  columns: S,
  onRowsChange: o
}) {
  const { getConfigColumns: h, size: p } = K(), { getLabel: k } = V(), { currentSize: x } = H(p), [f, l] = D(null), g = h("list");
  return {
    listContent: S.map((e, u) => {
      const w = g.find(
        (m) => m.key === e.key
      )?.showTitle !== !1;
      return /* @__PURE__ */ t(L, { ownerState: {}, children: /* @__PURE__ */ b(
        R,
        {
          ownerState: {},
          onDoubleClick: e.renderEditCell && f !== e.key ? () => {
            l(e.key);
          } : void 0,
          children: [
            w && /* @__PURE__ */ t(z, { ownerState: {}, variant: "bodyStandard", color: "text.secondary", children: e.name }),
            (() => {
              if (e.renderEditCell && f === e.key)
                return /* @__PURE__ */ t(I, { ownerState: { size: p }, children: e.renderEditCell({
                  column: e,
                  row: r,
                  rowIdx: u,
                  /**
                   * onRowChange es una función que se ejecuta cuando el usuario edita una celda.
                   */
                  onRowChange: (d) => {
                    if (o) {
                      const a = c.map(
                        (s, C) => C === n ? d : s
                      );
                      o(a, {
                        indexes: [n],
                        column: e
                      });
                    }
                  },
                  onClose: () => l(null)
                }) });
              if (e.renderCell) {
                const d = e.renderCell({
                  column: e,
                  row: r,
                  rowIdx: u,
                  isCellSelected: !1,
                  tabIndex: -1,
                  /**
                   * onRowChange es una función que se ejecuta cuando el usuario edita una celda.
                   */
                  onRowChange: (a) => {
                    if (o) {
                      const s = c.map(
                        (C, v) => v === n ? a : C
                      );
                      o(s, {
                        indexes: [n],
                        column: e
                      });
                    }
                  }
                });
                return /* @__PURE__ */ t(y, { ownerState: {}, variant: "bodyStandard", color: "text.primary", children: d });
              }
              const i = r[e.key], E = i == null || i === "";
              return e.renderEditCell ? /* @__PURE__ */ b(T, { ownerState: {}, children: [
                /* @__PURE__ */ t(
                  y,
                  {
                    ownerState: {},
                    variant: "bodyStandard",
                    color: E ? "text.secondary" : "text.primary",
                    children: E ? k(O.EDIT_PLACEHOLDER) : i
                  }
                ),
                /* @__PURE__ */ t(
                  A,
                  {
                    ownerState: {},
                    src: /* @__PURE__ */ t(j, {}),
                    onClick: () => {
                      l(e.key);
                    },
                    size: x,
                    role: "button",
                    "aria-label": "Editar texto"
                  }
                )
              ] }) : /* @__PURE__ */ t(y, { ownerState: {}, variant: "bodyStandard", color: "text.primary", children: r[e.key] ?? "-" });
            })()
          ]
        }
      ) }, e.key);
    }),
    columnsCount: S.length
  };
}
export {
  Q as useListContent
};
