import { getUserPreferences, setUserPreferences } from '@/modules/@common/user/helpers';
import { slice } from '@/modules/uploaderNew/redux/slices';

const nameSpace = slice.name;

const STORAGE = {
  feedName: 'selectedFeedName',
  contentOwner: 'selectedContentOwner',
  hubs: 'selectedHubs',
  accessLevel: 'selectedAccessLevel',
};

const getPreferences = () => getUserPreferences()?.[nameSpace];
const setPreferences = (param, value) => {
  const preferences = getPreferences();
  setUserPreferences(nameSpace, { ...preferences, [param]: value });
};
const buildPersist = (storageName) => ({
  set: (value) => setPreferences(storageName, value),
  get: () => getPreferences(storageName)?.[storageName],
});

export const persistFeedName = buildPersist(STORAGE.feedName);
export const persistHubs = buildPersist(STORAGE.hubs);
export const persistAccessLevel = buildPersist(STORAGE.accessLevel);
