import { TemplateResult, defaultTemplateProcessor } from 'lit-html';
import utils from '../utils';
export default class AbstractArena {
    constructor(options) {
        this.allowedAttributes = [];
        this.name = options.name;
        this.tag = options.tag;
        this.attributes = options.attributes;
        if (options.allowedAttributes) {
            this.allowedAttributes = options.allowedAttributes;
        }
        this.getOutputProcessor = options.output;
    }
    getTemplate(children, id, attributes) {
        if (!this.tag) {
            return children;
        }
        const strings = [];
        const values = [];
        if (this.tag) {
            const attrs = this.getAttributesString(id, attributes);
            const tag = this.tag.toLowerCase();
            strings.push(`<${tag} ${attrs} .arena="`);
            strings.push('">');
            strings.push(`</${tag}>`);
            values.push(this);
        }
        else {
            strings.push('');
            strings.push('');
        }
        values.push(children);
        // FIXME
        return new TemplateResult(strings, values, 'html', defaultTemplateProcessor);
    }
    getDataHtml(children, attributes, sigle = false) {
        if (!this.tag) {
            return children || '';
        }
        const openTag = this.getOpenTag(attributes);
        const closeTag = this.getCloseTag();
        let content = '';
        if (children) {
            content = sigle ? children : `\n${children}\n`;
        }
        return `${openTag}${content}${closeTag}`;
    }
    getOutput(type, children, attributes, node, frms) {
        if (this.getOutputProcessor) {
            return this.getOutputProcessor(type, node, frms, this.attributes);
        }
        const openTag = this.getOpenTag(attributes);
        const closeTag = this.getCloseTag();
        let content = '';
        if (children) {
            content = Array.isArray(children) ? children.join('\n') : `${children}`;
        }
        return `${openTag}${content}${closeTag}`;
    }
    getOpenTag(attributes) {
        if (!this.tag) {
            return '';
        }
        const attrs = this.getAttributesString('', attributes);
        const tag = this.tag.toLowerCase();
        return `<${tag}${attrs.length > 0 ? ` ${attrs}` : ''}>`;
    }
    getCloseTag() {
        if (!this.tag) {
            return '';
        }
        const tag = this.tag.toLowerCase();
        return `</${tag}>`;
    }
    getAttribute(name) {
        return this.attributes[name] || '';
    }
    getAttributesString(id, attributes) {
        let result = [];
        if (id) {
            result.push(`arena-id="${id}"`);
        }
        result = result.concat(utils.attr.getStringsFromAttributes(this.attributes));
        result = result.concat(utils.attr.getStringsFromAttributes(attributes));
        return result.join(' ');
    }
}
//# sourceMappingURL=AbstractArena.js.map