import ItemListingEntry from './ItemListingEntry.js';
import _Item from './_Item.js';

function ItemListing(initialVnode) {
  var chosen_images = {
    items: null,
    chosen_images: []
    };
  return {
    view: function(vnode) {
      //var items = _Item.filter(vnode.attrs.filter);
      //var items = _Item.collection;
      var items = vnode.attrs.items;
      if(items.length === 0){
        return m('h5', 'Please contact us directly to order.');
        }
      if(chosen_images.items !== items){
        chosen_images.chosen_images = items.map(function(item){
          return item.image_ids[0];
          });
        chosen_images.items = items;
        }
      return m(".columns", items.map(function(item, i){ 
          return m(ItemListingEntry, {item:item, index: i, chosen_images: chosen_images.chosen_images})
          }));
    }
  }
}
export default ItemListing