let data = []; let tabData = ''; const generateId = (data) => data.reduce((acc, current) => Math.max(acc, current.id), 0) + 1; export const insertItem = (item) => { console.log('item', item); item.id = generateId(data); item.inEdit = false; data.unshift(item); return data; }; export const getItems = () => { return data; }; export const updateItem = (item) => { let index = data.findIndex((record) => record.id === item.id); data[index] = item; return data; }; export const deleteItem = (item) => { let index = data.findIndex((record) => record.id === item.id); data.splice(index, 1); return data; }; export const setData = (initialData, tabName) => { tabData = tabName; data = initialData; };