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