import { Util } from '@ema/core';
import { AppService } from '../../global/app-service';
export class AppSwagger {
    constructor() {
        this.appService = AppService.instance;
        this.swaggerUrl = '/assets/data/apiSwagger.json';
    }
    componentWillLoad() {
        Util.fetchJson(this.swaggerUrl).then((res) => {
            this.loading = false;
            this.swagger = res;
            this.currentJsonObject = JSON.parse(JSON.stringify(res));
            console.log(this);
        });
    }
    parseSwaggerTypeAhead() {
        let searchData = [];
        this.swagger['tags'].forEach((tag) => {
            let obj = { "group": tag.name, "tags": [] };
            searchData.push(obj);
            Object.keys(this.swagger['paths']).forEach((k, i) => {
                let v = this.swagger['paths'][k];
                if (k.match(('/' + tag.name + '/'))) {
                    obj.tags.push(k);
                }
            });
        });
        return searchData;
    }
    onTypeAheadSelection(event) {
        console.log('onTypeAheadSelection');
        console.log(event.detail);
        this.currentJsonObject = JSON.parse(JSON.stringify(this.swagger.paths[event.detail.tag]));
    }
    onTypeAheadSearch(event) {
        console.log('onTypeAheadSearch');
        console.log(event.detail);
    }
    render() {
        console.log('render', this);
        return (h("div", { class: 'ema-app-swagger container' }, this.swagger &&
            h("div", null,
                h("h5", null, "api: swagger"),
                h("ema-type-ahead", { dataJson: JSON.stringify(this.parseSwaggerTypeAhead()), onSelection: ev => this.onTypeAheadSelection(ev), onSearch: ev => this.onTypeAheadSearch(ev) }),
                h("ema-json-viewer", { class: 'pt-3', dataJson: JSON.stringify(this.currentJsonObject), "allow-copy": 'true' }))));
    }
    static get is() { return "ema-app-swagger"; }
    static get properties() { return {
        "currentJsonObject": {
            "state": true
        },
        "isServer": {
            "context": "isServer"
        },
        "loading": {
            "state": true
        },
        "swagger": {
            "state": true
        }
    }; }
    static get style() { return "/**style-placeholder:ema-app-swagger:**/"; }
}
