
// src/order.js
import { state } from './state.js';

export async function loadAppOrder(Storage) {
  const stored = await Storage.loadAppsOrder();
  if (stored && Array.isArray(stored)) {
    state.appsOrder = stored.filter(id => state.appsData.some(a => a.id === id));
    state.appsData.forEach(a => { if (!state.appsOrder.includes(a.id)) state.appsOrder.push(a.id); });
  } else {
    state.appsOrder = state.appsData.map(a => a.id);
  }
}

export async function saveOrder(Storage) {
  await Storage.saveAppsOrder(state.appsOrder);
}
