import { TYPE_STRING, implementation } from './core'
import { ChildNodeAssembler } from './childnode'
import { DocumentAssembler } from './document'

const DEFAULT_PUBLIC_ID = ''
const DEFAULT_SYSTEM_ID = ''

/**
 * DocumentType DOM node assembler
 */
export class DocumentTypeAssembler extends ChildNodeAssembler {
    /**
     * @param {DocumentAssembler} parentNode
     */
    set parentNode(parentNode) {
        parentNode.node.prepend(this.node)
    }

    /**
     * @returns {DocumentAssembler}
     */
    get parentNode() {
        return super.parentNode
    }

    /**
     * Create the specified DocumentType node
     * @param {*} init
     * @returns {DocumentType}
     */
    static create(init) {
        if(typeof init === TYPE_STRING) {
            return implementation.createDocumentType(init, this.publicId, this.systemId)
        }
        else {
            const {
                qualifiedName = this.qualifiedName,
                publicId = this.publicId,
                systemId = this.systemId
            } = init || this
            return implementation.createDocumentType(qualifiedName, publicId, systemId)
        }
    }

    /**
     * @returns {String}
     */
    static get qualifiedName() {
        return DocumentTypeAssembler?
            DocumentAssembler.qualifiedName :
            this.name.toLowerCase()
    }

    /**
     * @returns {String}
     */
    static get publicId() {
        return DEFAULT_PUBLIC_ID
    }

    /**
     * @returns {String}
     */
    static get systemId() {
        return DEFAULT_SYSTEM_ID
    }
}

/**
 * DocumentType assembler factory
 * @param {Node|{}|String} [init]
 * @returns {DocumentTypeAssembler}
 */
export function doctype(...init) {
    return new DocumentTypeAssembler(...init)
}

@@ -579,54 +579,8 @@
 /**%0A
-     * Create the specified DocumentType node%0A
     
@@ -615,28 +615,20 @@
 eturns %7B
-DocumentType
+init
 %7D%0A     *
@@ -633,23 +633,16 @@
  */%0A    
-static 
 create(i
@@ -660,11 +660,15 @@
     
-if(
+return 
 type
@@ -690,19 +690,17 @@
 E_STRING
-) %7B
+?
 %0A       
@@ -708,138 +708,301 @@
     
-return implementation.createDocumentType(init, this.publicId, this.systemId)%0A        %7D%0A        else %7B
+super.create(%7B qualifiedName : init %7D) :%0A            super.create(init)%0A    %7D%0A%0A    /**%0A     * Create the specified DocumentType node%0A     * @param %7BString%7D qualifiedName%0A     * @param %7BString%7D publicId%0A     * @param %7BString%7D systemId%0A     * @returns %7BDocumentType%7D
 %0A     
-   
+*/%0A
     
-const %7B%0A        
+static create(%7B%0A
     
@@ -1049,24 +1049,16 @@
         
- 
-       
 publicId
@@ -1083,24 +1083,16 @@
         
-     
-   
 systemId
@@ -1116,37 +1116,20 @@
     
-        %7D = init %7C%7C this%0A    
+%7D = this) %7B%0A
     
@@ -1212,18 +1212,8 @@
 Id)%0A
-        %7D%0A
     

create properly