import { useState as l, useCallback as m, useEffect as n } from "react";
import { useIsMobile as p } from "@m4l/graphics";
import { getViewMode as b } from "../../helpers/persistence/getViewMode/getViewMode.js";
import { saveViewMode as S } from "../../helpers/persistence/saveViewMode/saveViewMode.js";
const x = ({
  id: r,
  viewMode: e,
  defaultViewMode: a,
  onViewModeChange: o,
  onChangeConfig: u
}) => {
  const c = p(), [f, s] = l(() => {
    if (e)
      return e;
    const t = b(r, null, a);
    return t || (c ? "cards" : "table");
  }), i = m(
    (t) => {
      s(t), S(r, t, u), o?.(t);
    },
    [r, o, u]
  );
  return n(() => {
    e !== void 0 && s(e);
  }, [e]), {
    viewModeState: f,
    setViewModeState: s,
    handleViewModeChange: i
  };
};
export {
  x as useViewMode
};
