/*************************************************************
 *
 *  Copyright (c) 2017 The MathJax Consortium
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

/**
 * @fileoverview  Implements the CHTMLsemantics wrapper for the MmlSemantics object
 *                and the associated wrappers for annotations
 *
 * @author dpvc@mathjax.org (Davide Cervone)
 */

import {CHTMLWrapper, CHTMLConstructor} from '../Wrapper.js';
import {CommonSemantics, CommonSemanticsMixin} from '../../common/Wrappers/semantics.js';
import {BBox} from '../BBox.js';
import {MmlSemantics, MmlAnnotation, MmlAnnotationXML} from '../../../core/MmlTree/MmlNodes/semantics.js';
import {MmlNode, XMLNode} from '../../../core/MmlTree/MmlNode.js';

/*****************************************************************/
/**
 * The CHTMLsemantics wrapper for the MmlSemantics object
 *
 * @template N  The HTMLElement node class
 * @template T  The Text node class
 * @template D  The Document class
 */
export class CHTMLsemantics<N, T, D> extends CommonSemanticsMixin<CHTMLConstructor<any, any, any>>(CHTMLWrapper) {

    public static kind = MmlSemantics.prototype.kind;

    /**
     * @override
     */
    public toCHTML(parent: N) {
        const chtml = this.standardCHTMLnode(parent);
        if (this.childNodes.length) {
            this.childNodes[0].toCHTML(chtml);
        }
    }

}


/*****************************************************************/
/**
 * The CHTMLannotation wrapper for the MmlAnnotation object
 *
 * @template N  The HTMLElement node class
 * @template T  The Text node class
 * @template D  The Document class
 */
export class CHTMLannotation<N, T, D> extends CHTMLWrapper<N, T, D> {
    public static kind = MmlAnnotation.prototype.kind;

    /**
     * @override
     */
    public toCHTML(parent: N) {
        // FIXME:  output as plain text
        super.toCHTML(parent);
    }

    /**
     * @override
     */
    public computeBBox() {
        // FIXME:  compute using the DOM, if possible
        return this.bbox;
    }

}

/*****************************************************************/
/**
 * The CHTMLannotationXML wrapper for the MmlAnnotationXML object
 *
 * @template N  The HTMLElement node class
 * @template T  The Text node class
 * @template D  The Document class
 */
export class CHTMLannotationXML<N, T, D> extends CHTMLWrapper<N, T, D> {
    public static kind = MmlAnnotationXML.prototype.kind;
}

/*****************************************************************/
/**
 * The CHTMLxml wrapper for the XMLNode object
 *
 * @template N  The HTMLElement node class
 * @template T  The Text node class
 * @template D  The Document class
 */
export class CHTMLxml<N, T, D> extends CHTMLWrapper<N, T, D> {
    public static kind = XMLNode.prototype.kind;

    public static autoStyle = false;

    /**
     * @override
     */
    public toCHTML(parent: N) {
        this.adaptor.append(parent, this.adaptor.clone((this.node as XMLNode).getXML() as N));
    }

    /**
     * @override
     */
    public computeBBox() {
        // FIXME:  compute using the DOM, if possible
        return this.bbox;
    }

    /**
     * @override
     */
    protected getStyles() {}

    /**
     * @override
     */
    protected getScale() {}

    /**
     * @override
     */
    protected getVariant() {}
}
