const DataStore = {
|
categories: [],
|
items: [],
|
categoryMap: {},
|
|
async load() {
|
const [catRes, itemRes] = await Promise.all([
|
fetch('config/categories.json'),
|
fetch('config/items.json')
|
]);
|
this.categories = await catRes.json();
|
this.items = await itemRes.json();
|
this.categoryMap = {};
|
this.categories.forEach(c => { this.categoryMap[c.id] = c; });
|
},
|
|
getCategory(id) {
|
return this.categoryMap[id];
|
},
|
|
getItemsByCategory(categoryId) {
|
return this.items.filter(i => i.categoryId === categoryId);
|
},
|
|
getLocalizedName(item) {
|
return I18n.t(item.nameKey);
|
},
|
|
getAllItemsLocalized() {
|
return this.items.map(item => ({
|
...item,
|
localName: this.getLocalizedName(item),
|
category: this.getCategory(item.categoryId)
|
}));
|
},
|
|
getCategoryName(categoryId) {
|
const cat = this.getCategory(categoryId);
|
return cat ? I18n.t(cat.nameKey) : '';
|
},
|
|
getCategoryColorClass(categoryId) {
|
const map = {
|
recyclable: 'text-recyclable',
|
hazardous: 'text-hazardous',
|
wet: 'text-wet',
|
dry: 'text-dry'
|
};
|
return map[categoryId] || '';
|
}
|
};
|