import { useCategory } from "@/modules";
import { css } from "@linaria/core";
import { Card } from "ant-design-vue";
import { defineComponent } from "vue";
import { useRoute } from "vue-router";
import DetailEditor from "./components/DetailEditor";
import DownloadEditor from "./components/DownloadEditor";
import ListEditor from "./components/ListEditor";

export default defineComponent({
  setup() {
    const route = useRoute();

    const categoryStore = useCategory();

    return () => {
      const id = route.params.id;
      const currCategory = categoryStore.listController.state.list.find(
        (e: CategoryItem) => {
          return e._id == id;
        }
      );
      return (
        <Card class={Page}>
          {currCategory?.type == "detail" && (
            <DetailEditor key={currCategory._id} data={currCategory} />
          )}
          {currCategory?.type == "list" && (
            <ListEditor key={currCategory._id} data={currCategory} />
          )}
          {currCategory?.type == "download" && (
            <DownloadEditor key={currCategory._id} data={currCategory} />
          )}
        </Card>
      );
    };
  },
});
const Page = css`
  height: 100%;
  .ant-card-body {
    height: 100%;
  }
`;
