// @ts-nocheck

// import 'phaser';
// import UIPlugin from 'phaser3-rex-plugins/templates/ui/ui-plugin';
import { COLOR_LIGHT, COLOR_PRIMARY, COLOR_DARK } from './Const';
import { DefaultDepth, DragObjectDepth } from './Const';
import CreateColumnPanelsBox from './CreateColumnPanelsBox';
import CreateHeader from './CreateHeader';
import AddResizeController from './AddResizeController';
import { TreeNode } from 'src/types/stores/kanvaso';
import CreateSwimlanePanelsBox from './CreateSwimlanePanelsBox';

type Scene = {
  rexUI: {
    add: {
      sizer: (config: SizerConfig) => Sizer;
    };
  };
};

type SizerConfig = {
  orientation: string;
  space: {
    left: number;
    right: number;
    top: number;
    bottom: number;
  };
};

type Sizer = {
  add: (item: any, config: any) => void;
};

const CreateScrollablePanel = (
  scene: Scene,
  board: TreeNode,
  registry: Phaser.Data.DataManager,
  size,
): ScrollablePanel => {
  const config: ScrollablePanelConfig = {
    adaptThumbSizeMode: true,
    width: size.w * 0.95,
    height: size.h * 0.95,
    background: scene.rexUI.add.roundRectangle({
      radius: 10,
      strokeColor: COLOR_DARK,
    }),
    panel: {
      child: CreateColumnPanelsBox(
        scene,
        board ? board?.childrens[0] : {},
        registry,
      ),
      mask: {
        padding: 2,
        updateMode: 'everyTick',
      },
    },
    sliderX: {
      track: { width: 20, radius: 10, color: COLOR_DARK },
      thumb: { radius: 13, color: COLOR_LIGHT },
      hideUnscrollableSlider: true,
      input: 'click',
    },
    sliderY: {
      track: { width: 20, radius: 10, color: COLOR_DARK },
      thumb: { radius: 13, color: COLOR_LIGHT },
      hideUnscrollableSlider: true,
      input: 'click',
    },
    scrollerX: false,
    scrollerY: false,
    space: {
      left: 10,
      right: 10,
      top: 10,
      bottom: 10,
      sliderX: 10,
      sliderY: 10,
    },
    header: CreateHeader(scene, board, registry),
  };

  // Создаем ScrollablePanel
  const scrollablePanel = scene.rexUI.add.scrollablePanel(config);

  // Устанавливаем возможность перетаскивания
  scrollablePanel.setDraggable('header');

  // Вызываем метод layout для обновления компоновки
  scrollablePanel.layout();

  // Добавляем контроллер для изменения размера
  AddResizeController(scrollablePanel);

  return scrollablePanel;
};

const CreateMoreScrollablePanels = (scene, boards, registry, size) => {
  const arr = [];
  boards.forEach((board) => {
    arr.push(CreateScrollablePanel(scene, board, registry, size));
  });
  return arr;
};

export default CreateMoreScrollablePanels as CreateScrollablePanel;
