/** @format */

import {create} from 'zustand';



export const useColorConfig = create((set, get) => ({
    state: {},
    getColors: () => {
        const res = localStorage.getItem('boxdialer-style')
        if (!!res) {
            let jsonRes = JSON.parse(res)
            set(() => ({state: jsonRes}))
        }
    },
    setColor: ({name, value}) => {
        const state = get()
        if (!!name) {
            set((state) => ({
                state: {
                    ...state.state,
                    [name]: value
                }
            }))
            state.saveToHistory()
        }
    },
    saveToHistory: () => {
        const state = get()
        localStorage.setItem('boxdialer-style', JSON.stringify(state.state))
    }
}));
