import { PageListController } from "@queenjs/controllers";
import { reactive } from "vue";

export class MaterialController  {
    state = reactive({isSelect:false, selectType:"image", currTab: "image", tabs:["image", "video", "task"], btns:["upload", "image","video"] , uploadType:"Default" as "image"|"video"|"Default"});
    imageCtrl = new PageListController<any, any>();
    vidoeCtrl = new PageListController<any, any>();
    taskCtrl = new PageListController<any, any>();
    tplCtrl = new PageListController<any, any>();

    async showDialog(type:string) {
        const ctrl = this.tplCtrl;
        ctrl.state.query = type == "video" ? { hasVideo: true } : {}
        ctrl.loadPage(1);
        const record:any = await this.onShowDialog(ctrl, type);
        if (record && record._id) {
            const url = `${location.origin}/index.html#/create/${record._id}`;
            location.href = url;
        }
    }
    switchTab(name: string, fresh = true) {
        this.state.currTab = name;
        const ctrol = this.getCurrControl();
        if(fresh)  ctrol.fresh();
    }
    getCurrControl() : PageListController<any, any> {
        switch (this.state.currTab) {
            case "image": return this.imageCtrl;
            case "video": return this.vidoeCtrl;
            default: return  this.taskCtrl;
        }
    }


    onBtnClick(name:string) {
        console.log("onBtnClick", name)
    }
    onItemClick(name: "delete" | "download" | "preview" |"use", record:any) {
        console.log("onItemClick", name, record)
    }
    async onShowDialog(listCtrl: PageListController<any, any>, type:string) {
        console.log("onShowDialog", type)
    }
     onCloseDialog(data:any) {
        console.log("onCloseDialog", data)
    }
}

export const TabNames = {
     "video":"视频",
    "image": "图片",
    "task": "渲染任务"
}
export const BtnNames = {
    "video":"生成视频",
    "image": "生成图片",
    "upload": "上传素材"
}
