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

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) {
        Model.cards.set(card.category_id+'.'+card.id, Object.assign({},card, {seen: false}));
      });
      store.set('loaded.cards', true);

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

  }
});

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