"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const configurator_1 = require("@iotize/device-client.js/configurator");
const xml_1 = require("@iotize/common/xml");
const data_accessor_1 = require("@iotize/common/data-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 configurator_1.TapConfigConverter().convert(new data_accessor_1.DotAccessor(xmlConfig));
    return config;
}
exports.fromXml = fromXml;
function iotizeStudioConfigToJson(fileContent) {
    return xml_1.xmlToJson(fileContent, {
        attributeNamePrefix: '',
        ignoreAttributes: false
    });
}
exports.iotizeStudioConfigToJson = iotizeStudioConfigToJson;
//# sourceMappingURL=tap-config-parser.js.map