"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const dot_accessor_1 = require("@iotize/device-admin.js/configuration/dot-accessor");
function convertIoTizeStudioPageConfig(pageInfo) {
    if (typeof pageInfo['enabled'] === "string") {
        pageInfo['enabled'] = pageInfo['enabled'] === "true";
    }
    let page = Object.assign({}, pageInfo);
    return page;
}
exports.convertIoTizeStudioPageConfig = convertIoTizeStudioPageConfig;
class IoTizeStudioConfigAdapter {
    static createProtocolConfigurationPage(accessor) {
        let page = convertIoTizeStudioPageConfig(accessor.data);
        return page;
    }
    static createAboutPage(accessor) {
        let page = convertIoTizeStudioPageConfig(accessor.data);
        return page;
    }
    static createTapInfoPage(accessor) {
        return {
            enabled: accessor.value('enabled', 'string', 'false') === "true",
            items: accessor.has('items') ? accessor.get('items').data : [],
            pageTitle: accessor.value('pageTitle', 'string', undefined)
        };
    }
    static renderOptionsToComponent(variable, renderOptions, isVariableEditable) {
        console.info('RENDER OPTIONS', renderOptions);
        let accessor = new dot_accessor_1.DotAccessor(renderOptions);
        let type = accessor.value('GUI_renderType', 'string');
        switch (type) {
            case 'Text':
                let textComponent = {
                    editable: isVariableEditable,
                    type: 'VariableText',
                    unit: variable.unit,
                    variable: `${variable.name}`
                };
                return textComponent;
            case 'Gauge':
                let gaugeComponent = {
                    editable: isVariableEditable,
                    type: 'VariableGauge',
                    unit: variable.unit,
                    variable: `${variable.name}`,
                    min: accessor.value('GUI_min', 'number', undefined),
                    max: accessor.value('GUI_max', 'number', undefined),
                };
                return gaugeComponent;
            case 'Buttons':
                let buttonChoicesString = accessor.value('GUI_listChoices', 'string', '');
                let buttonActions = buttonChoicesString.split(';')
                    .map((entryString => {
                    let [key, text] = entryString.split('=', 2);
                    return {
                        name: text,
                        value: parseInt(key)
                    };
                }));
                let buttonsComponent = {
                    editable: isVariableEditable,
                    type: 'VariableButtons',
                    unit: variable.unit,
                    variable: `${variable.name}`,
                    actions: buttonActions
                };
                return buttonsComponent;
            case 'OnOff':
                let toggleComponent = {
                    editable: isVariableEditable,
                    type: 'VariableToggle',
                    variable: `${variable.name}`,
                    conditionOn: `value !== 0`
                };
                return toggleComponent;
            default:
                return undefined;
        }
    }
}
exports.IoTizeStudioConfigAdapter = IoTizeStudioConfigAdapter;
//# sourceMappingURL=config-adapter.js.map