import { AsyncAuthAjax } from "./Ajax";
import { API } from "../dict/Consts";

cards.getArray = function() {
  const out = [];
  for(let key in this._props){
    if(key !== 'commit'){
      out.push(this._props[key]);
    }
  }
  return out;
};
store.sub('navigation.current', (val)=>tmpStore.set('navigation.current', val));

store.sub(['navigation.current', 'loaded.cards'], async function(page, loaded) {
  if(page !== 'Login' && !loaded){
    //try{
      const result = await AsyncAuthAjax.get( API.ENDPOINTS.GET_USER_NEW_CARDS() );

      result.forEach(function(card) {
        cards.set(card.id+'', {...card, seen: false})
      });
      store.set('loaded.cards', true);

    /*}catch(e){
      console.error(e)
    }*/

  }
});

tmpStore.sub([
  'isMobile', 'navigation.current'
], (is, page)=>{
  if(!is && page === 'Profile')
    store.set('navigation.current', 'Account');
});