import { lens } from '@dhmk/zustand-lens';
import { SetStateAction } from 'react';
import { BannerInfo } from './types';

export interface BannerInfoState {
  bannerInfo: BannerInfo;
  setBannerInfo: (update: SetStateAction<Partial<BannerInfo>>) => void;
};

const initialBannerInfoState = {
  bannerInfo: {} as BannerInfo,
} as BannerInfoState;

export const createBannerInfoStore = lens<BannerInfoState>((set, get) => ({
  ...initialBannerInfoState,
  setBannerInfo: (update) => {
    set((state: BannerInfoState) => {
      const newBannerInfo = (typeof update === 'function')
        ? update(state.bannerInfo): update;
      return {
        ...state,
        bannerInfo: {
          ...state.bannerInfo,
          ...newBannerInfo
        },
      };
    });
  },
  
}));
