import { useState as a, useCallback as d } from "react";
import { useWindowToolsMF as I } from "../../components/WindowBase/hooks/useWindowToolsMF/index.js";
import { getColumnsConfigListCookie as $, getColumnsConfigCardsCookie as N, getColumnsConfigCookie as k } from "./helpers.js";
import { COOKIE_VIEW_MODE as C, COOKIE_COLUMNS_CONFIG_LIST as s, COOKIE_COLUMNS_CONFIG_CARDS as e, COOKIE_COLUMNS_CONFIG as i, COOKIE_COLUMNS_WIDTHS as t } from "./constants.js";
const E = {
  columnsConfig: i,
  columnsConfigCards: e,
  columnsConfigList: s,
  columnsWidths: t,
  viewMode: C
}, K = (c) => {
  const { prefixCookie: o } = c, { setCookie: r, getCookie: n } = I(), [u] = a(() => ({
    columnsWidths: n(
      o ? `${o}_${t}` : t
    ) || {},
    columnsConfig: k(
      n(
        o ? `${o}_${i}` : i
      )
    ) || [],
    columnsConfigCards: N(
      n(
        o ? `${o}_${e}` : e
      )
    ) || [],
    columnsConfigList: $(
      n(
        o ? `${o}_${s}` : s
      )
    ) || [],
    viewMode: n(
      o ? `${o}_${C}` : C
    )
  })), m = d(
    (l) => {
      const { reason: O, userConfig: f } = l;
      if (f === void 0)
        return;
      const _ = E[O] ?? O, g = o ? `${o}_${_}` : _;
      r(g, "window", f);
    },
    [r, o]
  );
  return {
    // Nuevos nombres
    defaultConfig: u,
    onChangeConfig: m,
    // Deprecated aliases para backward compatibility
    defaultUserColumns: u,
    onChangeUserColumns: m
  };
};
export {
  K as useDataGridPersistence
};
