class WidgetGiveSlots extends R.TestView.WidgetGiveSlots {
    constructor() {
        super()
        this.childWidget = new R.TestView.WidgetWithSlots()
    }
}

export function run() {
    let wgs: WidgetGiveSlots
    let wis: R.TestView.WidgetWithSlots
    describe("Widget slot test", () => {
        it("Create widget", () => {
            wgs = new WidgetGiveSlots()
        })
        it("Can refer to data-id given to child widget", () => {
            let text = wgs.UI.header.textContent.toString().trim()
            if (text !== "HEADER") {
                throw new Error("Failed to reference")
            }
        })
        it("Should beable to merge child classes", () => {
            wgs.VM.parentClass = "parent-class"
            wgs.childWidget.VM.childClass = "child-class"
            let classes = ["parent-set-widget", "child-set-widget", "parent-class", "child-class"]
            for (let className of classes) {
                if (!wgs.childWidget.node.classList.contains(className)) {
                    throw new Error("Fail to merge child widget:" + className)
                }
            }
        })
        it("Child can refer to gived child widget by data-id", () => {
            let same = wgs.childWidget.UI.header === wgs.UI.header
            if (!same) {
                throw new Error("Failed to match header")
            }
            same = wgs.childWidget.UI.body === wgs.UI.body
            if (!same) {
                throw new Error("Failed to match body")
            }
        })
        it("Class should merge correctly", () => {
            wgs.VM.parentSlotClass = "parent-set"
            wgs.childWidget.VM.childSlotClass = "slot-set"
            let classes = ["parent-set", "slot-set", "slot-header", "parent-header"]
            for (let name of classes) {
                if (!wgs.childWidget.UI.header.classList.contains(name)) {
                    throw new Error("Fail to merge class:" + name)
                }
            }
        })
    })
    describe("Common widget test", () => {
        let tum: R.TestView.TestUseModal
        let tm: R.TestView.TestModal
        it("Widget include common widget", () => {
            Leaf.Widget.namespace.clear()
            Leaf.Widget.namespace.include(R.TestView.TestModal)
        })
        it("Widget use common widget", () => {
            tum = new R.TestView.TestUseModal()
            let succeed = tum.node.widget instanceof R.TestView.TestModal
            if (!succeed) {
                throw new Error("Fail to create namespace")
            }
            tm = tum.node.widget as any
        })
        it("Common widget should have dynamics properties attached", () => {
            tum.VM.parentHeaderSet = true
            tum.VM.useModalSet = true
            tm.VM.slotHeaderSet = true
            tm.VM.modalSet = true
            let classes: string[]
            classes = ["modal", "use-modal", "use-modal-set", "modal", "modal-set"]
            for (let name of classes) {
                if (!tum.node.classList.contains(name)) {
                    console.error(tum.node.classList)
                    throw new Error("Fail to transfer class:" + name)
                }
            }
            classes = ["parent-header", "parent-header-set", "slot-header", "slot-header-set"]
            for (let name of classes) {
                if (!tum.UI.header.classList.contains(name)) {
                    console.error(tum.UI.header.classList)
                    throw new Error("Fail to transfer slot class:" + name)
                }
            }
        })
    })
}
