"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tap_config_converter_1 = require("@iotize/device-admin.js/configuration/tap-config-converter");
const fast_xml_parser_1 = require("fast-xml-parser");
const dot_accessor_1 = require("@iotize/device-admin.js/configuration/dot-accessor");
function parseTapConfig(fileContent) {
    if (isJsonString(fileContent)) {
        let config = JSON.parse(fileContent);
        // this.tapConfigPickerservice.onConfigSelected(config);
        return config;
    }
    else {
        // if (IotizeConfigFactory.fromXML(fileContent)) {
        return fromXml(fileContent);
    }
}
exports.parseTapConfig = parseTapConfig;
function isJsonString(str) {
    try {
        var json = JSON.parse(str);
        return (typeof json === 'object');
    }
    catch (e) {
        return false;
    }
}
exports.isJsonString = isJsonString;
function fromXml(fileContent) {
    // console.log('File content', fileContent);
    let xmlConfig = iotizeStudioConfigToJson(fileContent);
    let config = new tap_config_converter_1.TapConfigConverter().convert(new dot_accessor_1.DotAccessor(xmlConfig));
    return config;
}
exports.fromXml = fromXml;
function iotizeStudioConfigToJson(fileContent) {
    return fast_xml_parser_1.parse(fileContent, {
        attributeNamePrefix: '',
        ignoreAttributes: false
    });
}
exports.iotizeStudioConfigToJson = iotizeStudioConfigToJson;
//# sourceMappingURL=tap-config-parser.js.map