import { COLOR_LIGHT, COLOR_PRIMARY, COLOR_DARK } from './Const';
import CreateColumnPanel from './CreateColumnPanel';
import AddDragDropColumnPanelBehavior from './AddDragDropColumnPanelBehavior';
import ObjectWrapper from 'src/utils/objectWrapper';
import { PanelsBoxType, EndlessCanvas } from 'src/types/kanban_types';
import { EventBus, Events } from 'src/boot/eventBus';

const CreateColumnPanelsBox = (
  scene: EndlessCanvas,
  swimlane: ObjectWrapper,
) => {
  const config = {
    orientation: 'x',
    space: {
      left: 10,
      right: 10,
      top: 10,
      bottom: 10,
    },
  };
  //@ts-ignore

  const columnPanelsBox = scene.rexUI.add.sizer(config) as PanelsBoxType;
  // .addBackground(
  //     scene.rexUI.add.roundRectangle({
  //         strokeColor: COLOR_PRIMARY,
  //         strokeWidth: 3,
  //     }),
  //     'background'
  // )
  const panelsBoxMap = new Map();

  if (swimlane && swimlane.childrens && swimlane.childrens.length > 0) {
    swimlane.childrens.forEach((column: ObjectWrapper) => {
      const columnPanel = CreateColumnPanel(scene, column);
      panelsBoxMap.set(column.uuid, columnPanel);

      columnPanelsBox.add(columnPanel, { proportion: 0, expand: true });
    });
  }

  AddDragDropColumnPanelBehavior(columnPanelsBox); // Убедитесь, что функция AddDragDropColumnPanelBehavior определена где-то в вашем коде
  EventBus.$on(Events.Delete, (uuid, object) => {
    if (panelsBoxMap.has(uuid)) {
      //@ts-ignore
      columnPanelsBox.remove(panelsBoxMap.get(uuid), true);
      columnPanelsBox.layout();
    }
  });
  return columnPanelsBox;
};

export default CreateColumnPanelsBox;
