import List from "@/components/AssetsList";
import { ComponentController } from "@/modules/resource/controllers/ComponentController";
import { defineUI } from "queenjs";
import { onMounted } from "vue";
import { any } from "vue-types";
import CompItem from "./CompItem";
import Header from "./Header";

export default defineUI({
  props: {
    Controller: any<ComponentController>().isRequired,
  },
  slots: {
    Header,
    List,
  },
  setup(props, { slots }) {
    onMounted(() => {
      props.Controller.ListCtrl.loadPage(1);
    });

    return () => {
      return (
        <div>
          <slots.Header onAdd={props.Controller.createComp} />
          <slots.List
            gap="25px"
            class="my-30px"
            columns={4}
            control={props.Controller.ListCtrl}
            item={(record: any) => (
              <CompItem
                record={record}
                onMenu={(name) => {
                  props.Controller.onMenuClick(name, record);
                }}
                onEdit={(record) => props.Controller.onEdit(record)}
              />
            )}
          />
        </div>
      );
    };
  },
});
