// import { COLOR_LIGHT, COLOR_PRIMARY, COLOR_DARK } from './Const';
import CreateItem from './CreateItem';
import AddDragDropItemBehavior from '../kanbans/AddDragDropItemBehavior';
import ObjectWrapper from 'src/utils/objectWrapper';
import { ItemsBoxType, EndlessCanvas } from 'src/types/kanban_types';
import { EventBus, Events } from 'src/boot/eventBus';
import { privateEncrypt } from 'crypto';

const CreateItemsBox = (scene: EndlessCanvas, cards: ObjectWrapper[]) => {
  const itemsBox = scene.rexUI.add.sizer({
    orientation: 'y',
    space: {
      left: 5,
      right: 5,
      top: 5,
      bottom: 5,
      item: 5,
    },
  }) as undefined as ItemsBoxType;
  //@ts-ignore

  itemsBox.addBackground(scene.rexUI.add.roundRectangle({}), 'background');
  const itemBoxMap = new Map();
  if (cards.length) {
    for (let i = 0; i < cards.length; i++) {
      const item = CreateItem(scene, cards[i]);
      itemBoxMap.set(cards[i].uuid, item);
      itemsBox.add(item, {
        proportion: 0,
        expand: true,
      });
    }
  }

  AddDragDropItemBehavior(itemsBox);
  EventBus.$on(Events.Delete, (uuid, object) => {
    if (itemBoxMap.has(uuid)) {
      //@ts-ignore
      itemsBox.remove(itemBoxMap.get(uuid), true);
      itemsBox.layout();
      itemsBox.getParentSizer().layout();
      itemsBox.getParentSizer().getParentSizer().layout();
    }
  });
  return itemsBox;
};

export default CreateItemsBox;
