import { EventEmitter, Component, Output, Input, NgModule } from '@angular/core';
import { __awaiter, __generator, __read, __assign, __values } from 'tslib';
import { FormBuilder, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ToastController } from '@ionic/angular';
import { TapInfo, PendingCallManager, LibError, CurrentDeviceService, LibCommonModule } from '@iotize/ionic';
import { createDebugger } from '@iotize/common/debug';
import { HostProtocol, TargetProtocol, TapResponse } from '@iotize/tap';
import { StringConverter } from '@iotize/tap/client/impl';
import { NfcConnectionPriority, NfcPairingMode } from '@iotize/tap/service/impl/interface';
import { WifiMode } from '@iotize/tap/service/impl/wifi';
import { ConnectionState } from '@iotize/tap/protocol/api';
import { DomElementAccessor } from '@iotize/common/data-accessor';
import { IoTizeStudioToTapConfigConverter } from '@iotize/tap/config/iotize-studio';

/**
 * @fileoverview added by tsickle
 * Generated from: lib/debug.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
/** @type {?} */
var debug = createDebugger('@iotize/ionic:config');

/**
 * @fileoverview added by tsickle
 * Generated from: lib/config.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
/** @type {?} */
var TAP_CONFIG_PATTERN = /^([0-9]+)\.([0-9]+)\.([0-9]+)$/;
/** @type {?} */
var IPV4_PATTERN = /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/;
/** @type {?} */
var SSID_PATTERN = /^[^!#;+\]\/"\t][^+\]\/"\t]{0,30}[^ !#;+\]\/"\t]$|^[^ !#;+\]\/"\t]$/;
/**
 * @param {?} pattern
 * @return {?}
 */
function regexValidator(pattern) {
    return (/**
     * @param {?} control
     * @return {?}
     */
    function (control) {
        /** @type {?} */
        var value = control.value;
        return !pattern.test(value) ? { 'invalidFormat': { value: control.value } } : null;
    });
}
/** @type {?} */
var validateTapVersion = regexValidator(TAP_CONFIG_PATTERN);
/**
 * @param {?} data
 * @return {?}
 */
function enumFormatter(data) {
    return (/**
     * @param {?} value
     * @return {?}
     */
    function (value) {
        if (Array.isArray(value)) {
            if (value.length == 0) {
                return '-';
            }
            return value.map((/**
             * @param {?} key
             * @return {?}
             */
            function (key) { return HostProtocol[key]; })).join(', ');
        }
        else {
            return (/** @type {?} */ (data[value]));
        }
    });
}
/**
 * @param {?} version
 * @return {?}
 */
function isTapConfigured(version) {
    return !(version.major == 0 && version.minor == 0 && version.patch == 0);
}
/**
 * @template T
 * @param {?} mapping
 * @return {?}
 */
function enumToOptions(mapping) {
    /** @type {?} */
    var keys = Object.keys(mapping).filter((/**
     * @param {?} k
     * @return {?}
     */
    function (k) { return typeof ((/** @type {?} */ (mapping)))[(/** @type {?} */ (k))] === 'number'; }));
    /** @type {?} */
    var result = keys.map((/**
     * @param {?} key
     * @return {?}
     */
    function (key) {
        return { key: ((/** @type {?} */ (mapping)))[key], text: key };
    }));
    // console.log('enumToOptions', result);
    return result;
}
/**
 * @template T
 * @param {?} v
 * @param {?} mapping
 * @return {?}
 */
function stringToEnumArray(v, mapping) {
    return v.split(',').map((/**
     * @param {?} item
     * @return {?}
     */
    function (item) { return item.trim(); })).map(((/**
     * @param {?} item
     * @return {?}
     */
    function (item) {
        if (!(item in mapping)) {
            throw new Error("Invalid value \"" + item + "\". Must one of the follwing: " + Object.keys(mapping).join(', '));
        }
        return (/** @type {?} */ ((/** @type {?} */ (mapping[(/** @type {?} */ (item))]))));
    })));
}
var ɵ0 = /**
 * @param {?} tap
 * @return {?}
 */
function (tap) { return tap.service.device.getSerialNumber(); }, ɵ1 = /**
 * @param {?} tap
 * @return {?}
 */
function (tap) { return tap.service.device.getFirmwareFlavor(); }, ɵ2 = /**
 * @param {?} tap
 * @return {?}
 */
function (tap) { return tap.service.device.getManufacturer(); }, ɵ3 = /**
 * @param {?} tap
 * @return {?}
 */
function (tap) {
    return tap.service.interface.getCurrentHostProtocol();
}, ɵ4 = /**
 * @param {?} tap
 * @param {?} protocol
 * @return {?}
 */
function (tap, protocol) {
    return tap.service.interface.putCurrentHostProtocol(protocol);
};
/** @type {?} */
var defaultInfoResolverConfig = [
    {
        key: TapInfo.serialNumber,
        title: 'Serial number',
        description: 'Unique identifier for your Tap',
        editable: false,
        getValue: (ɵ0)
    },
    {
        key: TapInfo.modelName,
        title: 'Model name',
        description: 'Tap model\'s name',
        editable: false,
        getValue: (ɵ1)
    },
    {
        key: TapInfo.tapManufacturer,
        title: 'Manufacturer',
        description: 'Name of the Tap manufacturer',
        editable: false,
        getValue: (ɵ2)
    },
    {
        key: TapInfo.HostProtocol,
        title: 'Protocol',
        description: 'Communication protocol between your TapNLink and your application',
        getValue: (ɵ3),
        putValue: (ɵ4),
        input: {
            type: 'select',
            options: enumToOptions(HostProtocol)
        },
        viewFormatter: enumFormatter(HostProtocol)
    },
    {
        key: TapInfo.appName,
        title: 'Application name',
        description: 'Also used when broadcasting with BLE or Wi-Fi',
        input: {
            maxLength: 32
        },
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return tap.service.interface.getAppName(); }),
        putValue: (/**
         * @param {?} tap
         * @param {?} value
         * @return {?}
         */
        function (tap, value) {
            return tap.service.interface.putAppName(value);
        })
    },
    {
        key: TapInfo.configVersion,
        title: 'Tap configuration version',
        description: 'Tap configuration version loaded on your device',
        input: {
            pattern: TAP_CONFIG_PATTERN
        },
        viewFormatter: (/**
         * @param {?} v
         * @return {?}
         */
        function (v) {
            if (v) {
                return "v" + v;
            }
            else {
                return 'Not configured';
            }
        }),
        formValidators: [
            validateTapVersion
        ],
        editFormatter: {
            read: (/**
             * @param {?} input
             * @return {?}
             */
            function (input) {
                console.log('Read Tap version', input);
                /** @type {?} */
                var parts = input.split('.');
                return {
                    major: parseInt(parts[0], 10),
                    minor: parseInt(parts[1], 10),
                    patch: parseInt(parts[2], 10)
                };
            }),
            write: (/**
             * @param {?} v
             * @return {?}
             */
            function (v) {
                return v ? v.major + "." + v.minor + "." + v.patch : '0.0.0';
            })
        },
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return tap.service.interface.getConfigVersion(); }),
        putValue: (/**
         * @param {?} tap
         * @param {?} version
         * @return {?}
         */
        function (tap, version) {
            // const versionNumber = (v.major << 24) | (v.minor << 16) | v.patch;
            // console.log('As version number: ', versionNumber);
            return tap.service.interface.putConfigVersion(version);
        })
    },
    {
        title: 'Minimal transmission period',
        description: 'Used as an indication for mobile application wether or not it should send data log packets to the cloud',
        key: TapInfo.CloudUploadPeriod,
        viewFormatter: (/**
         * @param {?} v
         * @return {?}
         */
        function (v) { return v + " ms"; }),
        input: {
            type: 'number'
        },
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return tap.service.cloud.getDataLogUploadPeriod(); }),
        putValue: (/**
         * @param {?} tap
         * @param {?} value
         * @return {?}
         */
        function (tap, value) {
            return __awaiter(this, void 0, void 0, function () {
                var result;
                return __generator(this, function (_a) {
                    if (typeof value === 'string') {
                        value = parseInt(value, 10);
                    }
                    result = tap.service.cloud.putDataLogUploadPeriod(value);
                    return [2 /*return*/, result];
                });
            });
        })
    },
    {
        title: 'MQTT broker',
        description: 'Mqtt broker used for synchronization ',
        key: TapInfo.CloudEndpoint,
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return __awaiter(void 0, void 0, void 0, function () {
            var hostname, port;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, tap.service.mqtt.getBrokerHostname()];
                    case 1:
                        hostname = (_a.sent()).body();
                        return [4 /*yield*/, tap.service.mqtt.getBrokerPort()];
                    case 2:
                        port = (_a.sent()).body();
                        return [2 /*return*/, hostname + ":" + port];
                }
            });
        }); }),
        putValue: (/**
         * @param {?} tap
         * @param {?} value
         * @return {?}
         */
        function (tap, value) { return __awaiter(void 0, void 0, void 0, function () {
            var _a, hostname, port, setPort;
            return __generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        _a = __read(value.split(':'), 2), hostname = _a[0], port = _a[1];
                        return [4 /*yield*/, tap.service.mqtt.putBrokerPort(port || '1883')];
                    case 1:
                        setPort = _b.sent();
                        setPort.successful();
                        return [2 /*return*/, tap.service.mqtt.putBrokerHostname(hostname)];
                }
            });
        }); })
    },
    {
        title: 'Cloud key',
        description: 'Cloud key used for authentification',
        key: TapInfo.CloudKey,
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return tap.service.mqtt.getPassword(); }),
        putValue: (/**
         * @param {?} tap
         * @param {?} value
         * @return {?}
         */
        function (tap, value) { return __awaiter(void 0, void 0, void 0, function () {
            var result;
            return __generator(this, function (_a) {
                result = tap.service.mqtt.putPassword(value);
                return [2 /*return*/, result];
            });
        }); })
    },
    // {
    //     title: 'MQTT endpoint',
    //     description: 'MQTT endpoint used',
    //     key: TapInfo.MqttEndpoint,
    //     input: {
    //         maxLength: 128
    //     },
    //     getValue: async (tap) => {
    //         const hostname = (await tap.service.mqtt.getBrokerHostname()).body();
    //         const port = (await tap.service.mqtt.getBrokerPort()).body();
    //         return `${hostname}:${port}`;
    //     },
    //     putValue: async function (tap: Tap, value: string) {
    //         const [hostname, port] = value.split(':');
    //         await tap.service.mqtt.putBrokerPort(port);
    //         return await tap.service.mqtt.putBrokerHostname(value);
    //     }
    // },
    {
        title: 'MQTT broker hostname',
        description: 'MQTT broker hostname (for exemple user.cloud.iotize.com)',
        key: TapInfo.MqttBrokerHostname,
        input: {
            maxLength: 128
        },
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
            return [2 /*return*/, tap.service.mqtt.getBrokerHostname()];
        }); }); }),
        putValue: (/**
         * @param {?} tap
         * @param {?} value
         * @return {?}
         */
        function (tap, value) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
            return [2 /*return*/, tap.service.mqtt.putBrokerHostname(value)];
        }); }); })
    },
    {
        title: 'MQTT broker port',
        description: 'MQTT broker port (for exemple 1883 or 8883)',
        key: TapInfo.MqttBrokerPort,
        input: {
            maxLength: 128,
            type: 'number'
        },
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
            return [2 /*return*/, tap.service.mqtt.getBrokerPort()];
        }); }); }),
        putValue: (/**
         * @param {?} tap
         * @param {?} value
         * @return {?}
         */
        function (tap, value) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
            return [2 /*return*/, tap.service.mqtt.putBrokerPort(value.toString())];
        }); }); })
    },
    {
        title: 'MQTT password',
        description: 'Mqtt password',
        key: TapInfo.MqttPassword,
        input: {
            maxLength: 32
        },
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return __awaiter(void 0, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, tap.service.mqtt.getPassword()];
                    case 1: return [2 /*return*/, (_a.sent()).body()];
                }
            });
        }); }),
        putValue: (/**
         * @param {?} tap
         * @param {?} value
         * @return {?}
         */
        function (tap, value) {
            return __awaiter(this, void 0, void 0, function () {
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0: return [4 /*yield*/, tap.service.mqtt.putPassword(value)];
                        case 1: return [2 /*return*/, _a.sent()];
                    }
                });
            });
        })
    },
    {
        title: 'MQTT relay net key',
        description: 'Mqtt relay net key',
        key: TapInfo.MqttRelayNetKey,
        input: {
            maxLength: 32
        },
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return __awaiter(void 0, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, tap.service.mqtt.getRelayNetKey()];
                    case 1: return [2 /*return*/, (_a.sent()).body()];
                }
            });
        }); }),
        putValue: (/**
         * @param {?} tap
         * @param {?} value
         * @return {?}
         */
        function (tap, value) {
            return __awaiter(this, void 0, void 0, function () {
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0: return [4 /*yield*/, tap.service.mqtt.putRelayNetKey(value)];
                        case 1: return [2 /*return*/, _a.sent()];
                    }
                });
            });
        })
    },
    // {
    //     title: 'MQTT service name',
    //     description: 'MQTT service name',
    //     key: TapInfo.MqttServiceName,
    //     input: {
    //         maxLength: 32
    //     },
    //     getValue: async (tap) => {
    //         return (await tap.service.mqtt.getBrokerPort()).body();
    //     },
    //     putValue: async function (tap: Tap, value: string) {
    //         return await tap.service.mqtt.putBrokerPort(value);
    //     }
    // },
    {
        title: 'MQTT client id',
        description: 'Unique identifier of the client. Can be anything you want but it must be uniq. \
        Only one client with the same id can be connected at the same time',
        key: TapInfo.MqttClientId,
        input: {
            maxLength: 32
        },
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return __awaiter(void 0, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, tap.service.mqtt.getClientId()];
                    case 1: return [2 /*return*/, (_a.sent()).body()];
                }
            });
        }); }),
        putValue: (/**
         * @param {?} tap
         * @param {?} value
         * @return {?}
         */
        function (tap, value) {
            return __awaiter(this, void 0, void 0, function () {
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0: return [4 /*yield*/, tap.service.mqtt.putClientId(value)];
                        case 1: return [2 /*return*/, _a.sent()];
                    }
                });
            });
        })
    },
    {
        title: 'MQTT password',
        description: 'MQTT password',
        input: {
            maxLength: 128
        },
        key: TapInfo.MqttPassword,
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) {
            return tap.service.mqtt.getPassword();
        }),
        putValue: (/**
         * @param {?} tap
         * @param {?} val
         * @return {?}
         */
        function (tap, val) {
            return tap.service.mqtt.putPassword(val);
        })
    },
    {
        title: 'MQTT username',
        description: 'MQTT username',
        input: {
            maxLength: 32
        },
        key: TapInfo.MqttUsername,
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) {
            return tap.service.mqtt.getUsername();
        }),
        putValue: (/**
         * @param {?} tap
         * @param {?} val
         * @return {?}
         */
        function (tap, val) {
            return tap.service.mqtt.putUsername(val);
        })
    },
    {
        title: 'NFC priority',
        description: 'Enable if NFC has priority over other protocols. \
        It means that a new NFC connection will force disconnection of other connected clients. ',
        input: {
            type: 'toggle',
        },
        key: TapInfo.NFCConnectionPriority,
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return __awaiter(void 0, void 0, void 0, function () {
            var value;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, tap.service.interface.getNfcConnectionPriority()];
                    case 1:
                        value = (_a.sent()).body();
                        return [2 /*return*/, value === NfcConnectionPriority.NFC_PRIORITY];
                }
            });
        }); }),
        putValue: (/**
         * @param {?} tap
         * @param {?} val
         * @return {?}
         */
        function (tap, val) {
            /** @type {?} */
            var mode = val ? NfcConnectionPriority.NFC_NON_PRIORITY : NfcConnectionPriority.NFC_PRIORITY;
            return tap.service.interface.putNfcConnectionPriority(mode);
        })
    },
    {
        title: 'NFC mandatory to connect to the Tap',
        description: 'Choose whether or not NFC must be used to connect to the Tap. ',
        input: {
            type: 'select',
            options: [
                {
                    key: NfcPairingMode.NO,
                    text: 'No',
                },
                {
                    key: NfcPairingMode.MANDATORY,
                    text: 'Yes',
                },
                {
                    key: NfcPairingMode.MANDATORY_FOR_LOGIN,
                    text: 'Only to login',
                }
            ]
        },
        key: TapInfo.NFCPairingMode,
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) {
            return tap.service.interface.getNfcPairingMode();
        }),
        putValue: (/**
         * @param {?} tap
         * @param {?} val
         * @return {?}
         */
        function (tap, val) {
            return tap.service.interface.putNfcPairingMode(val);
        })
    },
    {
        title: 'Packet count',
        description: 'The current number of data log packet in memory',
        key: TapInfo.DataLogPacketCount,
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return tap.service.dataLog.getPacketCount(); })
    },
    {
        title: 'Maximum packet count',
        description: 'Maximum number of data log packet the Tap is able to store',
        key: TapInfo.DataLogMaxPacketCount,
        viewFormatter: (/**
         * @param {?} v
         * @return {?}
         */
        function (v) {
            return v == 0 ? 'NO LIMIT' : v.toString();
        }),
        input: {
            type: 'number'
        },
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return tap.service.dataLog.getMaxPacketCount(); })
        // putValue: (tap: Tap, value: number) => {
        //     return tap.service.dataLog.putMaxPacketCount()
        // }
    },
    {
        title: 'Target connected',
        description: 'Wether or not Tap is connected to the target application',
        key: TapInfo.IsTargetConnected,
        // viewFormatter: (v: boolean) => v ? 'YES' : 'NO',
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return tap.service.target.isConnected(); }),
        putValue: (/**
         * @param {?} tap
         * @param {?} enabled
         * @return {?}
         */
        function (tap, enabled) {
            if (enabled) {
                return tap.service.target.connect();
            }
            else {
                return tap.service.target.disconnect();
            }
        }),
        input: {
            type: 'toggle'
        }
    },
    {
        title: 'Universal link',
        description: 'Will be used for iOS app',
        key: TapInfo.universalLink,
        icon: 'link',
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return tap.service.interface.getUniversalLink(); }),
        putValue: (/**
         * @param {?} tap
         * @param {?} value
         * @return {?}
         */
        function (tap, value) {
            return tap.service.interface.putUniversalLink(value);
        })
    },
    {
        title: 'Android application record',
        description: 'For example "com.iotize.app.tapmanager"',
        key: TapInfo.androidApplicationRecord,
        // TODO replace with getAndroidApplicationId()
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return __awaiter(void 0, void 0, void 0, function () {
            var appPath;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, tap.service.interface.getAppPath()];
                    case 1:
                        appPath = (_a.sent()).body();
                        if (appPath.startsWith('$4/')) {
                            return [2 /*return*/, appPath.substring(3)];
                        }
                        else {
                            return [2 /*return*/, false];
                        }
                        return [2 /*return*/];
                }
            });
        }); }),
        putValue: (/**
         * @param {?} tap
         * @param {?} value
         * @return {?}
         */
        function (tap, value) { return __awaiter(void 0, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, tap.service.interface.putAppPath("$4/" + value)];
            });
        }); })
    },
    {
        title: 'Encryption',
        description: 'If enabled, it will use encryption for communication between the mobile device \
        (smartphone, PC, ...) and your TapNLink',
        key: TapInfo.useEncryption,
        input: {
            type: 'toggle'
        },
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return __awaiter(void 0, void 0, void 0, function () {
            var lockOptions;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, tap.service.interface.getSecurityOptions()];
                    case 1:
                        lockOptions = (_a.sent()).body();
                        return [2 /*return*/, lockOptions.scramActivated];
                }
            });
        }); })
    },
    {
        title: 'Encryption iteration number',
        description: 'Number of iteration for encryption algorithm. Higher it is, the more secure it gets',
        key: TapInfo.scramIterationNumber,
        input: {
            type: 'number',
            min: 0,
            max: 0xFFFF
        },
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return __awaiter(void 0, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, tap.service.scram.getHashIteration()];
                    case 1: return [2 /*return*/, (_a.sent()).body()];
                }
            });
        }); })
    },
    {
        title: 'Authorized hardware factory reset',
        description: 'If enabled, user can perform a hardware factory reset',
        key: TapInfo.lockFactoryReset,
        input: {
            type: 'toggle'
        },
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return __awaiter(void 0, void 0, void 0, function () {
            var lockOptions;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, tap.service.interface.getSecurityOptions()];
                    case 1:
                        lockOptions = (_a.sent()).body();
                        return [2 /*return*/, !lockOptions.disableHardwareFactoryReset];
                }
            });
        }); })
    },
    {
        title: 'Use password hash',
        description: 'If true, user passwords will be stored as hash',
        key: TapInfo.hashPassword,
        input: {
            type: 'toggle'
        },
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return __awaiter(void 0, void 0, void 0, function () {
            var lockOptions;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, tap.service.interface.getSecurityOptions()];
                    case 1:
                        lockOptions = (_a.sent()).body();
                        return [2 /*return*/, lockOptions.hashPassword];
                }
            });
        }); })
    },
    {
        title: 'Authorize login with UID',
        description: 'If enabled, it will authorized a user to log in as an administrator using a unique identifier',
        key: TapInfo.isLoginWithUIDEnabled,
        input: {
            type: 'toggle'
        },
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return __awaiter(void 0, void 0, void 0, function () {
            var lockOptions;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, tap.service.interface.getSecurityOptions()];
                    case 1:
                        lockOptions = (_a.sent()).body();
                        return [2 /*return*/, !lockOptions.disableLoginWithUID];
                }
            });
        }); })
    },
    {
        title: 'Authorize factory reset using LWM2M',
        description: 'If enabled, it will authorized an administrator user to do a factory reset using the API',
        key: TapInfo.isLWM2MFactoryResetEnabled,
        input: {
            type: 'toggle'
        },
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return __awaiter(void 0, void 0, void 0, function () {
            var lockOptions;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, tap.service.interface.getSecurityOptions()];
                    case 1:
                        lockOptions = (_a.sent()).body();
                        return [2 /*return*/, !lockOptions.disableResourceFactoryReset];
                }
            });
        }); })
    },
    {
        title: 'Security options',
        description: 'Security options',
        key: TapInfo.lockOptions,
        putValue: (/**
         * @param {?} tap
         * @param {?} value
         * @return {?}
         */
        function (tap, value) {
            return tap.service.interface.putSecurityOptions(value);
        }),
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) {
            return tap.service.interface.getSecurityOptions();
        })
    },
    {
        title: 'Application path',
        description: 'Contains the path to the application to load when connecting to this device. It may be an application id or a website URL.',
        key: TapInfo.appPath,
        putValue: (/**
         * @param {?} tap
         * @param {?} value
         * @return {?}
         */
        function (tap, value) {
            return tap.service.interface.putAppPath(value);
        }),
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return tap.service.interface.getAppPathResolved(); })
    },
    {
        title: 'Username',
        description: 'Username used for login',
        key: TapInfo.ProfileName,
        getValue: (/**
         * @param {?} tap
         * @param {?} groupId
         * @return {?}
         */
        function (tap, groupId) {
            return tap.service.group.getName(groupId);
        }),
        putValue: (/**
         * @param {?} tap
         * @param {?} value
         * @param {?} groupId
         * @return {?}
         */
        function (tap, value, groupId) {
            return tap.service.group.putName(groupId, value);
        })
    },
    {
        title: 'Parent group ID',
        description: 'Identifier of group from where this user inherits his rights',
        key: TapInfo.parentGroupId,
        getValue: (/**
         * @param {?} tap
         * @param {?} groupId
         * @return {?}
         */
        function (tap, groupId) {
            return tap.service.group.getAlias(groupId);
        }),
        putValue: (/**
         * @param {?} tap
         * @param {?} value
         * @param {?} groupId
         * @return {?}
         */
        function (tap, value, groupId) {
            return tap.service.group.putAlias(groupId, value);
        })
    },
    {
        title: 'Clear data log packet store',
        description: 'This action cannot be undone',
        getValue: false,
        key: TapInfo.DataLogClearPacketStore,
        actions: [
            {
                title: 'Clear',
                icon: 'trash',
                call: (/**
                 * @param {?} tap
                 * @return {?}
                 */
                function (tap) {
                    return tap.service.dataLog.flush();
                })
            }
        ]
    },
    {
        title: 'Session life time',
        description: 'Duration of the session in seconds (it does not apply right away, it will only be used on following logins)',
        key: TapInfo.ProfileSessionLifeTime,
        getValue: (/**
         * @param {?} tap
         * @param {?} groupId
         * @return {?}
         */
        function (tap, groupId) {
            return tap.service.group.getSessionLifetime(groupId);
        }),
        putValue: (/**
         * @param {?} tap
         * @param {?} value
         * @param {?} groupId
         * @return {?}
         */
        function (tap, value, groupId) {
            return tap.service.group.putSessionLifetime(groupId, value);
        })
    },
    {
        title: 'Target protocol',
        description: 'Communication protocol used between the Tap and the micro controller',
        key: TapInfo.TargetProtocol,
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) {
            return tap.service.target.getProtocol();
        }),
        putValue: (/**
         * @param {?} tap
         * @param {?} protocol
         * @return {?}
         */
        function (tap, protocol) {
            return tap.service.target.putProtocol(protocol);
        }),
        // TODO
        setValue: (/**
         * @param {?} tap
         * @param {?} protocol
         * @return {?}
         */
        function (tap, protocol) {
            return tap.service.target.setProtocol(protocol);
        }),
        viewFormatter: enumFormatter(TargetProtocol),
        input: {
            type: 'select',
            options: enumToOptions(TargetProtocol)
                .filter((/**
             * @param {?} f
             * @return {?}
             */
            function (f) {
                return f.key !== TargetProtocol.JTAG;
            }))
        }
    },
    {
        title: 'Available protocols',
        description: 'Communication protocols available on your device',
        key: TapInfo.availableHostProtocols,
        viewFormatter: enumFormatter(HostProtocol),
        editFormatter: {
            write: (/**
             * @param {?} v
             * @return {?}
             */
            function (v) {
                // console.log('Host protocols: ', v);
                if (!v || v.length === 0) {
                    return 'NONE';
                }
                return v.map((/**
                 * @param {?} key
                 * @return {?}
                 */
                function (key) { return HostProtocol[key]; })).join(', ');
            }),
            read: (/**
             * @param {?} v
             * @return {?}
             */
            function (v) {
                return stringToEnumArray(v, HostProtocol);
            })
        },
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return tap.service.interface.getAvailableHostProtocols(); })
    },
    {
        title: 'Authorized protocols',
        description: 'Communication protocols authorized on your device',
        key: TapInfo.authorizedHostProtocols,
        input: {
            type: 'select',
            multiple: true,
            options: []
        },
        viewFormatter: enumFormatter(HostProtocol),
        // (v: HostProtocol[]) => {
        //     if (!v || v.length == 0) {
        //         return 'NONE'
        //     }
        //     return v.map(key => HostProtocol[key]).join(', ');
        // },
        // editFormatter: {
        //     write: (v: HostProtocol[]): string => {
        //         if (!v || v.length == 0) {
        //             return 'NONE'
        //         }
        //         return v.map(key => HostProtocol[key]).join(', ');
        //     },
        //     read: (v: string): HostProtocol[] => {
        //         let protocols: HostProtocol[] = stringToEnumArray<HostProtocol>(v, HostProtocol);
        //         return protocols;
        //     }
        // },
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return tap.service.interface.getAuthorizedHostProtocol(); }),
        putValue: (/**
         * @param {?} tap
         * @param {?} protocols
         * @return {?}
         */
        function (tap, protocols) {
            return tap.service.interface.putAuthorizedHostProtocol(protocols);
        }),
        init: (/**
         * @param {?} service
         * @param {?} config
         * @return {?}
         */
        function (service, config) { return __awaiter(void 0, void 0, void 0, function () {
            var hostProtocols;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, service
                            .getValue(TapInfo.availableHostProtocols)];
                    case 1:
                        hostProtocols = _a.sent();
                        (/** @type {?} */ (config.input)).options = hostProtocols.map((/**
                         * @param {?} key
                         * @return {?}
                         */
                        function (key) {
                            return { key: key, text: HostProtocol[key] };
                        }));
                        return [2 /*return*/];
                }
            });
        }); })
    },
    {
        title: 'Enable/Disable data log acquisition on your device',
        key: TapInfo.DataLogToggleAcquisition,
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) {
            return tap.service.dataLog.isRunning();
        }),
        actions: [
            {
                title: 'start',
                icon: 'play',
                color: 'primary',
                call: (/**
                 * @param {?} tap
                 * @return {?}
                 */
                function (tap) { return tap.service.dataLog.run(); }),
                triggersRefresh: [
                    TapInfo.DatalogAcquisitionRunning
                ]
            },
            {
                title: 'stop',
                icon: 'pause',
                color: 'danger',
                call: (/**
                 * @param {?} tap
                 * @return {?}
                 */
                function (tap) { return tap.service.dataLog.stop(); }),
                triggersRefresh: [
                    TapInfo.DatalogAcquisitionRunning
                ]
            }
        ]
    },
    {
        key: TapInfo.BundleDatalogPeriod,
        title: 'Data log acquisition period',
        description: 'Define variable value acquisition period (in milliseconds)',
        input: {
            type: 'number'
        },
        getValue: (/**
         * @param {?} tap
         * @param {?} bundleId
         * @return {?}
         */
        function (tap, bundleId) {
            if (bundleId === undefined) {
                throw new Error("Missing paramater bundleId");
            }
            return tap.service.bundle.getDataLogPeriod(bundleId);
        }),
        putValue: (/**
         * @param {?} tap
         * @param {?} value
         * @param {?} bundleId
         * @return {?}
         */
        function (tap, value, bundleId) {
            if (bundleId === undefined) {
                throw new Error("Missing paramater bundleId");
            }
            return tap.service.bundle.putDataLogPeriod(bundleId, value);
        })
    },
    {
        key: TapInfo.configPath,
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return tap.service.interface.getConfigPath(); }),
        title: 'Configuration file path'
    },
    // {
    //     key: TapInfo.isTapConfigured,
    //     title: 'Tap is configured',
    //     input: {
    //         type: 'toggle'
    //     },
    //     getValue: async function (tap: Tap) {
    //         let version = (await tap.service.interface.getConfigVersion()).body();
    //         return !(version.major == 0 && version.minor == 0 && version.patch == 0);
    //     },
    //     editable: false
    // },
    {
        key: TapInfo.tapFirmwareVersion,
        title: 'Tap firmware version',
        description: 'IoTize Tap firmware version currently loaded on the Tap',
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return tap.service.device.getFirmwareVersion(); })
    },
    {
        key: TapInfo.DatalogAcquisitionRunning,
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return tap.service.dataLog.isRunning(); }),
        title: 'Data log acquision running',
        description: 'Is data log acquisition running'
    },
    {
        key: TapInfo.AdpStats,
        title: 'ADP info',
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return tap.service.tapnpass.getStatus(); })
    },
    {
        key: TapInfo.AdpVersion,
        title: 'ADP version',
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return tap.service.tapnpass.getStatus(); }),
        viewFormatter: (/**
         * @param {?} stats
         * @return {?}
         */
        function (stats) {
            /** @type {?} */
            var v = stats.header.version;
            return v.major + "." + v.minor + "." + v.patch;
        }),
        editable: false
    },
    {
        key: TapInfo.SinglePacketInfo,
        title: 'Single packet info',
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) {
            return tap.service.singlePacket.getInfo();
        })
    },
    {
        key: TapInfo.protocolHostInactivityPeriod,
        title: 'Disconnection inactivity delay',
        description: 'Duration (in seconds) after which the Tap will disconnect the connected client if there is no communication',
        input: {
            type: 'number',
            min: 0,
            max: 255
        },
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) {
            return tap.service.interface.getHostInactivityPeriod();
        }),
        putValue: (/**
         * @param {?} tap
         * @param {?} value
         * @return {?}
         */
        function (tap, value) {
            return tap.service.interface.putHostInactivityPeriod(value);
        })
    },
    {
        key: TapInfo.bleMacAddress,
        title: 'BLE Mac address',
        description: 'For example: "C4:A2:EF:45:23"',
        editable: false,
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) {
            return tap.service.ble.getAddress();
        })
    },
    {
        key: TapInfo.WifiHostname,
        title: 'Current Tap IP/Hostname',
        description: 'IPV4 address',
        editable: false,
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) {
            return tap.service.wifi.getHostname();
        }),
        viewFormatter: (/**
         * @param {?} v
         * @return {?}
         */
        function (v) {
            if (v === '0.0.0.0') {
                return 'NO IP';
            }
            return v;
        })
    },
    {
        key: TapInfo.WifiSSID,
        title: 'Wi-Fi SSID',
        description: 'Wifi SSID (Service Set IDentifier)',
        editable: false,
        input: {
            minLength: 1,
            maxLength: 32
        },
        formValidators: [
            regexValidator(SSID_PATTERN)
        ],
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) {
            return tap.service.wifi.getSSID();
        }),
        putValue: (/**
         * @param {?} tap
         * @param {?} value
         * @return {?}
         */
        function (tap, value) {
            return tap.service.wifi.putSSID(value);
        })
    },
    {
        key: TapInfo.NetworkInfraIp,
        title: 'Wi-Fi IP',
        description: 'Use ip address 0.0.0.0 if you want to let Tap use DHCP to obtain an IP address',
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return tap.service.wifi.getIp(); }),
        putValue: (/**
         * @param {?} tap
         * @param {?} value
         * @return {?}
         */
        function (tap, value) { return tap.service.wifi.putIp(value); }),
        formValidators: [
            regexValidator(IPV4_PATTERN)
        ],
        viewFormatter: (/**
         * @param {?} value
         * @return {?}
         */
        function (value) {
            if (value === '0.0.0.0') {
                return 'Dynamic (DHCP)';
            }
            return value;
        })
    },
    {
        key: TapInfo.NetworkGatewayIp,
        title: 'Wi-Fi gateway IP address',
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) { return tap.service.wifi.getGatewayIp(); }),
        formValidators: [
            regexValidator(IPV4_PATTERN)
        ]
    },
    {
        key: TapInfo.WifiMode,
        title: 'Wi-Fi mode',
        description: 'Your Tap can either connect to an existing Wi-Fi network or behave as a network',
        editable: false,
        input: {
            type: 'select',
            // options: enumToOptions(WifiMode),
            options: [
                {
                    icon: 'git-network',
                    key: WifiMode.NETWORK,
                    text: 'Network'
                },
                {
                    icon: 'people',
                    key: WifiMode.PEER_TO_PEER,
                    text: 'Access point'
                }
            ]
        },
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) {
            return tap.service.wifi.getMode();
        }),
        putValue: (/**
         * @param {?} tap
         * @param {?} value
         * @return {?}
         */
        function (tap, value) {
            return tap.service.wifi.putMode(value);
        })
    },
    {
        key: TapInfo.isHostProtocolAuthorized,
        title: 'Authorized',
        description: 'Enable to authorized the given protocol to be used to connect to this device',
        editable: false,
        input: {
            type: 'toggle'
        },
        getValue: (/**
         * @param {?} tap
         * @param {?} protocol
         * @return {?}
         */
        function (tap, protocol) { return __awaiter(void 0, void 0, void 0, function () {
            var protocols;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        if (protocol === undefined) {
                            throw new Error("Illegal argument error: missing protocol");
                        }
                        return [4 /*yield*/, tap.service.interface.getAuthorizedHostProtocol()];
                    case 1:
                        protocols = (_a.sent()).body();
                        return [2 /*return*/, protocols.find((/**
                             * @param {?} p
                             * @return {?}
                             */
                            function (p) { return p === protocol; })) !== undefined];
                }
            });
        }); }),
        putValue: (/**
         * @param {?} tap
         * @param {?} value
         * @param {?} protocol
         * @return {?}
         */
        function (tap, value, protocol) { return __awaiter(void 0, void 0, void 0, function () {
            var protocols, indexOfProtocol;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, tap.service.interface.getAuthorizedHostProtocol()];
                    case 1:
                        protocols = (_a.sent()).body();
                        if (protocol === undefined) {
                            throw new Error("Illegal argument error: missing protocol");
                        }
                        indexOfProtocol = protocols.findIndex((/**
                         * @param {?} p
                         * @return {?}
                         */
                        function (p) { return p == protocol; }));
                        if (value) {
                            if (indexOfProtocol == -1) {
                                protocols.push(protocol);
                            }
                        }
                        else {
                            if (indexOfProtocol >= 0) {
                                protocols.splice(indexOfProtocol, 1);
                            }
                        }
                        return [2 /*return*/, tap.service.interface.putAuthorizedHostProtocol(protocols)];
                }
            });
        }); })
    },
    {
        key: TapInfo.WifiKey,
        title: 'Wi-Fi key',
        description: 'Wi-Fi key',
        editable: false,
        input: {
            type: 'password',
            minLength: 8,
            maxLength: 128
        },
        getValue: (/**
         * @param {?} tap
         * @return {?}
         */
        function (tap) {
            return tap.service.wifi.getKey();
        }),
        putValue: (/**
         * @param {?} tap
         * @param {?} value
         * @return {?}
         */
        function (tap, value) {
            return tap.service.wifi.putKey(value);
        })
    },
    {
        key: TapInfo.bundleName,
        title: 'Bundle name',
        description: 'Friendly bundle name to display',
        editable: false,
        input: {
            minLength: 1,
            maxLength: 16
        },
        getValue: (/**
         * @param {?} tap
         * @param {?} bundleId
         * @return {?}
         */
        function (tap, bundleId) {
            return tap.service.bundle.getName(bundleId);
        }),
        putValue: (/**
         * @param {?} tap
         * @param {?} value
         * @param {?} bundleId
         * @return {?}
         */
        function (tap, value, bundleId) {
            return tap.service.bundle.putName(bundleId, value);
        })
    },
    {
        key: TapInfo.variableMetaData,
        title: 'Variable meta name',
        description: 'Additional variable data',
        editable: false,
        input: {},
        getValue: (/**
         * @param {?} tap
         * @param {?} variableId
         * @return {?}
         */
        function (tap, variableId) { return __awaiter(void 0, void 0, void 0, function () {
            var metaData;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, tap.service.variable.getRawMeta(variableId)];
                    case 1:
                        metaData = (_a.sent()).body();
                        return [2 /*return*/, StringConverter.ascii().decode(metaData)];
                }
            });
        }); }),
        putValue: (/**
         * @param {?} tap
         * @param {?} value
         * @param {?} bundleId
         * @return {?}
         */
        function (tap, value, bundleId) {
            /** @type {?} */
            var data = StringConverter.ascii().encode(value);
            return tap.service.variable.putRawMeta(bundleId, data);
        })
    },
    {
        key: TapInfo.profilePassword,
        title: 'User password',
        description: 'New user password',
        editable: false,
        input: {
            type: 'password',
            minLength: 1,
            maxLength: 16
        },
        viewFormatter: (/**
         * @param {?} value
         * @return {?}
         */
        function (value) {
            return '********';
        }),
        putValue: (/**
         * @param {?} tap
         * @param {?} value
         * @param {?=} profileId
         * @return {?}
         */
        function (tap, value, profileId) { return __awaiter(void 0, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, tap.auth.changePassword(value, profileId)];
                    case 1:
                        (_a.sent());
                        return [2 /*return*/, TapResponse.SUCCESS()]; // TODO fix
                }
            });
        }); })
    }
];

/**
 * @fileoverview added by tsickle
 * Generated from: lib/tap-config-item/tap-config-item.component.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
/**
 * @template ValueType
 */
var TapConfigItemComponent = /** @class */ (function () {
    function TapConfigItemComponent(formBuilder, tapService, toastController) {
        this.tapService = tapService;
        this.toastController = toastController;
        this.focusOut = new EventEmitter();
        this.onSubmit = new EventEmitter();
        this.refresh = false;
        this.loading = false;
        this.placeholder = '';
        this.editMode = false;
        this.displayedValue = '';
        this.form = formBuilder.group({
            field: ['']
        });
        this.pendingCallManager = PendingCallManager
            .create(this.tapService);
    }
    Object.defineProperty(TapConfigItemComponent.prototype, "info", {
        get: /**
         * @return {?}
         */
        function () {
            return this.config;
        },
        set: /**
         * @param {?} config
         * @return {?}
         */
        function (config) {
            /** @type {?} */
            var defaultConfig = defaultInfoResolverConfig.find((/**
             * @param {?} v
             * @return {?}
             */
            function (v) { return config.key === v.key; }));
            if (defaultConfig) {
                config = __assign(__assign({}, defaultConfig), config);
            }
            this._config = config;
            if (config.params && !this.params) {
                this.params = config.params;
            }
            if (config.formValidators) {
                this.field.setValidators(config.formValidators);
            }
            this.updateDisplayValue();
            this.fetchValueIfRequired();
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TapConfigItemComponent.prototype, "hasButtons", {
        get: /**
         * @return {?}
         */
        function () {
            return this.refresh || this.editable || this.pendingEditCall;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TapConfigItemComponent.prototype, "originalValue", {
        get: /**
         * @return {?}
         */
        function () {
            var _a;
            return (_a = this.config.resolvedValue) === null || _a === void 0 ? void 0 : _a.value;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TapConfigItemComponent.prototype, "field", {
        get: /**
         * @return {?}
         */
        function () {
            /** @type {?} */
            var control = this.form.get('field');
            if (!control) {
                throw LibError.missingFromField('TapConfigItemComponent', 'field');
            }
            return control;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TapConfigItemComponent.prototype, "config", {
        get: /**
         * @return {?}
         */
        function () {
            if (!this._config) {
                throw LibError.componentArgumentRequired('TapConfigItemComponent', 'info');
            }
            return this._config;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TapConfigItemComponent.prototype, "inputOptions", {
        get: /**
         * @return {?}
         */
        function () {
            return this.info.input || {};
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TapConfigItemComponent.prototype, "editable", {
        get: /**
         * @return {?}
         */
        function () {
            return this.config.editable;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TapConfigItemComponent.prototype, "pendingEditCall", {
        get: /**
         * @return {?}
         */
        function () {
            return this.pendingCallManager.pendingCall;
        },
        enumerable: true,
        configurable: true
    });
    /**
     * @return {?}
     */
    TapConfigItemComponent.prototype.ngOnInit = /**
     * @return {?}
     */
    function () {
        var _this = this;
        // this.pendingTapCall.register(this);
        // this.tapService.registerEventListerner(this);
        this.initializeConfig();
        /** @type {?} */
        var params = this.params || this.config.params;
        if (this.config.input && this.config.input.type === 'password') {
            this.setDisplayValue((/** @type {?} */ ('')));
        }
        this.valueSubscription = this.tapService
            .getKeyInfo$(this.config.key, params)
            .subscribe((/**
         * @param {?} newValue
         * @return {?}
         */
        function (newValue) {
            _this.config.resolvedValue = newValue;
            if (newValue.error) {
                _this.setError(newValue.error);
            }
            else {
                _this.error = undefined;
                _this.setDisplayValue(newValue.value);
                _this.setFieldValue(newValue.value);
            }
        }));
        // this.sessionStateSubscription = this.tapService.sessionState.subscribe((newState) => {
        //   if (newState.name !== 'anonymous') {
        //     this._runPendingCalls();
        //   }
        // })
    };
    /**
     * @return {?}
     */
    TapConfigItemComponent.prototype.initializeConfig = /**
     * @return {?}
     */
    function () {
        var _this = this;
        if (this.config.init) {
            this.config.init(this.tapService, this.config)
                .catch((/**
             * @param {?} err
             * @return {?}
             */
            function (err) {
                _this.setError(err);
            }));
        }
    };
    /**
     * @param {?} error
     * @return {?}
     */
    TapConfigItemComponent.prototype.setError = /**
     * @param {?} error
     * @return {?}
     */
    function (error) {
        // this.setFieldValue((error.message || 'Unknown error') as any as ValueType);
        this.error = error;
    };
    /**
     * @return {?}
     */
    TapConfigItemComponent.prototype.ngOnDestroy = /**
     * @return {?}
     */
    function () {
        var _a;
        // this.tapService.unregisterEventListener(this);
        (_a = this.valueSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
        this.pendingCallManager.destroy();
        // this.pendingTapCall.unregister(this);
    };
    /**
     * @return {?}
     */
    TapConfigItemComponent.prototype.close = /**
     * @return {?}
     */
    function () {
    };
    /**
     * @param {?} $event
     * @return {?}
     */
    TapConfigItemComponent.prototype.submit = /**
     * @param {?} $event
     * @return {?}
     */
    function ($event) {
        var _this = this;
        this.field.updateValueAndValidity();
        if (!this.field.valid) {
            this.error = new Error("Invalid value");
            return;
        }
        // this.onSubmit.emit(event);
        /** @type {?} */
        var value = this.getFieldValue();
        // debug(`Creating call new value:`, value, `valid: ${this.field.valid}`)
        /** @type {?} */
        var params = this.params || this.config.params;
        /** @type {?} */
        var call = (/**
         * @return {?}
         */
        function () { return __awaiter(_this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.tapService.putInfo(this.info.key, value, params)];
                    case 1:
                        _a.sent();
                        return [2 /*return*/, value];
                }
            });
        }); });
        this.runCall(call);
    };
    /**
     * @private
     * @param {?} call
     * @return {?}
     */
    TapConfigItemComponent.prototype.runCall = /**
     * @private
     * @param {?} call
     * @return {?}
     */
    function (call) {
        var _this = this;
        this.loading = true;
        this.pendingCallManager
            .exec(call)
            .then((/**
         * @param {?} value
         * @return {?}
         */
        function (value) {
            _this.showToast("Value saved!", 'success');
            _this.config.resolvedValue = {
                loadDate: new Date(),
                value: value
            };
            _this.error = undefined;
            _this.editMode = false;
            _this.updateDisplayValue();
        }))
            .catch((/**
         * @param {?} err
         * @return {?}
         */
        function (err) {
            _this.error = err;
            _this.field.setErrors({
                'write': err.message
            });
        }))
            .finally((/**
         * @return {?}
         */
        function () {
            _this.loading = false;
        }));
    };
    /**
     * @return {?}
     */
    TapConfigItemComponent.prototype.onValueClick = /**
     * @return {?}
     */
    function () {
        if (this.editable) {
            this.editMode = true;
        }
    };
    /**
     * @return {?}
     */
    TapConfigItemComponent.prototype.explainPendingCall = /**
     * @return {?}
     */
    function () {
        this.showToast('Please reconnect your Tap to save pending changes');
    };
    /**
     * @return {?}
     */
    TapConfigItemComponent.prototype.onFocusOut = /**
     * @return {?}
     */
    function () {
        this.focusOut.emit(this.field.value);
    };
    /**
     * @return {?}
     */
    TapConfigItemComponent.prototype.isEdited = /**
     * @return {?}
     */
    function () {
        return this.field.value != this.originalValue;
    };
    /**
     * @param {?=} $event
     * @return {?}
     */
    TapConfigItemComponent.prototype.cancelEdit = /**
     * @param {?=} $event
     * @return {?}
     */
    function ($event) {
        debug(this.config.key, 'cancel edit');
        if (this.pendingCallManager.hasPendingCall()) {
            this.pendingCallManager.cancel();
            this.error = undefined;
        }
        else {
            this.error = undefined;
            // if ($event) {
            //   $event.target.blur();
            // }
            this.editMode = false;
            this.restaureValue();
        }
    };
    /**
     * @return {?}
     */
    TapConfigItemComponent.prototype.getFieldValue = /**
     * @return {?}
     */
    function () {
        /** @type {?} */
        var fieldValue = this.field.value;
        if (this.config.editFormatter) {
            fieldValue = this.config.editFormatter.read(fieldValue);
        }
        return fieldValue;
    };
    // setValue(value: any) {
    //   debug(`Set value`, value);
    //   this.displayedValue = this.resolveValueForView();
    //   if (this._info.editFormatter) {
    //     value = this._info.editFormatter.write(value);
    //   }
    //   // let formValue = this.field.value;
    //   this.field.setValue(
    //     value
    //   );
    // }
    // setValue(value: any) {
    //   debug(`Set value`, value);
    //   this.displayedValue = this.resolveValueForView();
    //   if (this._info.editFormatter) {
    //     value = this._info.editFormatter.write(value);
    //   }
    //   // let formValue = this.field.value;
    //   this.field.setValue(
    //     value
    //   );
    // }
    /**
     * @param {?} msg
     * @param {?=} color
     * @return {?}
     */
    TapConfigItemComponent.prototype.showToast = 
    // setValue(value: any) {
    //   debug(`Set value`, value);
    //   this.displayedValue = this.resolveValueForView();
    //   if (this._info.editFormatter) {
    //     value = this._info.editFormatter.write(value);
    //   }
    //   // let formValue = this.field.value;
    //   this.field.setValue(
    //     value
    //   );
    // }
    /**
     * @param {?} msg
     * @param {?=} color
     * @return {?}
     */
    function (msg, color) {
        return __awaiter(this, void 0, void 0, function () {
            var toast;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.toastController.create({
                            message: msg,
                            duration: 2000,
                            position: 'bottom',
                            color: color
                        })];
                    case 1:
                        toast = _a.sent();
                        toast.present();
                        return [2 /*return*/];
                }
            });
        });
    };
    /**
     * @return {?}
     */
    TapConfigItemComponent.prototype.refreshValue = /**
     * @return {?}
     */
    function () {
        return this._execRefreshKey();
    };
    /**
     * @private
     * @return {?}
     */
    TapConfigItemComponent.prototype._execRefreshKey = /**
     * @private
     * @return {?}
     */
    function () {
        return this.tapService.infoResolver.refreshKey(this.config.key, this.params || this.config.params);
    };
    /**
     * @return {?}
     */
    TapConfigItemComponent.prototype.restaureValue = /**
     * @return {?}
     */
    function () {
        this.setFieldValue(this.originalValue);
    };
    /**
     * @param {?} value
     * @return {?}
     */
    TapConfigItemComponent.prototype.setFieldValue = /**
     * @param {?} value
     * @return {?}
     */
    function (value) {
        /** @type {?} */
        var formattedValue = this.config.editFormatter ? this.config.editFormatter.write(value) : value;
        debug(this.config.key, "setFieldValue with", formattedValue);
        this.field.setValue(formattedValue);
    };
    /**
     * @return {?}
     */
    TapConfigItemComponent.prototype.updateDisplayValue = /**
     * @return {?}
     */
    function () {
        if (this.config.resolvedValue) {
            if (this.config.resolvedValue.error) {
                this.displayedValue = this.config.resolvedValue.error.message;
            }
            else {
                /** @type {?} */
                var value = this.config.resolvedValue.value;
                this.setDisplayValue(value);
                this.setFieldValue(value);
            }
        }
        else {
            debug(this.config.key, "Value is not loaded yet", this.config.resolvedValue);
        }
        // TODO loading
    };
    /**
     * @param {?} value
     * @return {?}
     */
    TapConfigItemComponent.prototype.setDisplayValue = /**
     * @param {?} value
     * @return {?}
     */
    function (value) {
        var _a, _b;
        if (value instanceof Error) {
            return value.message;
        }
        else {
            /** @type {?} */
            var stringValue = void 0;
            if (this.config.viewFormatter) {
                stringValue = this.config.viewFormatter(value);
            }
            else if (typeof value === 'object') {
                stringValue = JSON.stringify(value);
            }
            else if (((_a = this.config.input) === null || _a === void 0 ? void 0 : _a.type) === 'select') {
                stringValue = ((_b = this.getSelectedOption(value)) === null || _b === void 0 ? void 0 : _b.text) || (value !== undefined ? ((/** @type {?} */ (value))).toString() : '');
            }
            else {
                stringValue = value !== undefined ? ((/** @type {?} */ (value))).toString() : '';
            }
            // debug(`${this.config.key} setDisplayValue with`, stringValue);
            this.displayedValue = stringValue;
            return stringValue;
        }
    };
    /**
     * @param {?} value
     * @return {?}
     */
    TapConfigItemComponent.prototype.getSelectedOption = /**
     * @param {?} value
     * @return {?}
     */
    function (value) {
        var _a, _b;
        return (_b = (_a = this.config.input) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.find((/**
         * @param {?} option
         * @return {?}
         */
        function (option) { return option.key === value; }));
    };
    Object.defineProperty(TapConfigItemComponent.prototype, "selectedOption", {
        get: /**
         * @return {?}
         */
        function () {
            var _a;
            return this.getSelectedOption((_a = this.config.resolvedValue) === null || _a === void 0 ? void 0 : _a.value);
        },
        enumerable: true,
        configurable: true
    });
    /**
     * @return {?}
     */
    TapConfigItemComponent.prototype.fetchValueIfRequired = /**
     * @return {?}
     */
    function () {
        if (!this.config.resolvedValue) {
            this.fetchValue();
        }
    };
    /**
     * @return {?}
     */
    TapConfigItemComponent.prototype.fetchValue = /**
     * @return {?}
     */
    function () {
        if (this.config.getValue) {
            this.tapService.infoResolver.refreshKey(this.config.key, this.params);
        }
    };
    TapConfigItemComponent.decorators = [
        { type: Component, args: [{
                    selector: 'tap-config-item',
                    template: "<ion-item [formGroup]=\"form\" [lines]=\"editable ? '' : 'none'\">\r\n    <ion-toggle *ngIf=\"inputOptions.type === 'toggle'; else viewEditSeparated\" [disabled]=\"!editMode || loading || pendingEditCall\" formControlName=\"field\"></ion-toggle>\r\n    <ng-template #viewEditSeparated>\r\n        <ng-container [ngSwitch]=\"inputOptions.type\" *ngIf='!editMode' >\r\n            <div (click)='onValueClick()' *ngSwitchCase=\"'select'\" [class]=\"editable ? 'cell': ''\">\r\n                <ion-icon *ngIf=\"selectedOption?.icon\" [name]=\"selectedOption?.icon\"></ion-icon>\r\n                <ion-text>\r\n                    {{ displayedValue }}\r\n                </ion-text>\r\n            </div>\r\n            <ion-text  (click)='onValueClick()' *ngSwitchDefault [class]=\"editable ? 'cell': ''\">\r\n                {{ displayedValue }}\r\n            </ion-text>\r\n        </ng-container>\r\n        <ng-container *ngIf='editMode' [ngSwitch]=\"inputOptions.type\">\r\n            <ion-select *ngSwitchCase=\"'select'\" formControlName=\"field\" [multiple]=\"inputOptions.multiple\">\r\n                <ion-select-option *ngFor=\"let option of inputOptions.options\" [value]=\"option.key\">\r\n                    <ion-icon *ngIf=\"option.icon\" [name]=\"option.icon\"></ion-icon> {{option.text}}\r\n                </ion-select-option>\r\n            </ion-select>\r\n            <ion-input *ngSwitchDefault (keydown.enter)='submit($event)'\r\n                 (keydown.escape)='cancelEdit($event)' \r\n                 [disabled]=\"pendingEditCall\" \r\n                 [maxlength]=\"inputOptions.maxLength\" \r\n                 [minlength]=\"inputOptions.minLength\" \r\n                 [max]=\"inputOptions.max\" \r\n                 [min]=\"inputOptions.min\" \r\n                 [pattern]=\"inputOptions.pattern\" \r\n                 [placeholder]=\"placeholder\" \r\n                 [type]=\"inputOptions.type\" \r\n                 appAutofocus \r\n                 class='cellInput' \r\n                 formControlName=\"field\">\r\n            </ion-input>\r\n        </ng-container>\r\n    </ng-template>\r\n    <ion-buttons *ngIf=\"hasButtons\" slot=\"end\">\r\n            <ion-button (click)=\"explainPendingCall()\" *ngIf=\"pendingEditCall\" [disabled]=\"false\" color=\"warning\">\r\n                <ion-icon name=\"alert\"></ion-icon>\r\n            </ion-button>\r\n        <ng-container *ngIf=\"editable; then EditableButtons; else NotEditableButtons\"></ng-container>\r\n        <ng-template #EditableButtons>\r\n            <ion-button (click)='editMode=true' *ngIf=\"!editMode && info.putValue\">\r\n                <ion-icon name=\"create\"></ion-icon>\r\n            </ion-button>\r\n            <ion-button (click)=\"submit($event)\" *ngIf=\"editMode && !pendingEditCall\" [disabled]=\"loading || pendingEditCall\">\r\n                <ion-icon name=\"send\"></ion-icon>\r\n            </ion-button>\r\n            <ion-button (click)=\"cancelEdit()\" *ngIf=\"editMode\" [disabled]=\"loading\">\r\n                <ion-icon name=\"close\"></ion-icon>\r\n            </ion-button>\r\n        </ng-template>\r\n        <ng-template #NotEditableButtons>\r\n        </ng-template>\r\n        <ion-button (click)=\"refreshValue()\" *ngIf=\"refresh && info.getValue\" [disabled]=\"loading\">\r\n            <ion-icon name=\"sync\"></ion-icon>\r\n        </ion-button>\r\n    </ion-buttons>\r\n    <ion-spinner *ngIf=\"loading\" slot=\"end\"></ion-spinner>\r\n</ion-item>\r\n<ion-item *ngIf=\"error\">\r\n    <ion-text color=\"danger\">\r\n        <ion-icon name=\"alert\"></ion-icon>\r\n        {{error.message}}\r\n    </ion-text>\r\n</ion-item>\r\n",
                    styles: [".cell{border:2px solid transparent;padding:11px 0;width:100%;height:100%}.cell:hover{cursor:pointer;border:2px dashed #c8c8c8}ion-item{--padding-start:0px}.cellInput{border:2px solid transparent;padding:11px 20px;width:100%;height:100%}ion-select{min-width:150px}"]
                }] }
    ];
    /** @nocollapse */
    TapConfigItemComponent.ctorParameters = function () { return [
        { type: FormBuilder },
        { type: CurrentDeviceService },
        { type: ToastController }
    ]; };
    TapConfigItemComponent.propDecorators = {
        focusOut: [{ type: Output }],
        onSubmit: [{ type: Output }],
        params: [{ type: Input }],
        info: [{ type: Input }],
        refresh: [{ type: Input }],
        editMode: [{ type: Input }]
    };
    return TapConfigItemComponent;
}());
if (false) {
    /** @type {?} */
    TapConfigItemComponent.prototype.focusOut;
    /** @type {?} */
    TapConfigItemComponent.prototype.onSubmit;
    /** @type {?} */
    TapConfigItemComponent.prototype.pendingCallManager;
    /** @type {?} */
    TapConfigItemComponent.prototype.params;
    /** @type {?} */
    TapConfigItemComponent.prototype.refresh;
    /**
     * @type {?}
     * @private
     */
    TapConfigItemComponent.prototype.valueSubscription;
    /** @type {?} */
    TapConfigItemComponent.prototype.form;
    /** @type {?} */
    TapConfigItemComponent.prototype._config;
    /** @type {?} */
    TapConfigItemComponent.prototype.loading;
    /** @type {?} */
    TapConfigItemComponent.prototype.error;
    /** @type {?} */
    TapConfigItemComponent.prototype.placeholder;
    /** @type {?} */
    TapConfigItemComponent.prototype.editMode;
    /** @type {?} */
    TapConfigItemComponent.prototype.displayedValue;
    /**
     * @type {?}
     * @private
     */
    TapConfigItemComponent.prototype.tapService;
    /**
     * @type {?}
     * @private
     */
    TapConfigItemComponent.prototype.toastController;
}

/**
 * @fileoverview added by tsickle
 * Generated from: lib/tap-config-list/tap-config-list.component.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var TapConfigListComponent = /** @class */ (function () {
    function TapConfigListComponent(tapService, toastController) {
        this.tapService = tapService;
        this.toastController = toastController;
        // dataSource: DeviceInfoDataSource;
        this.header = undefined;
        this.globalRefresh = true;
        this.itemRefresh = false;
        this.lines = 'full';
        this.columns = [
            'key',
            'value'
            // , 'action'
        ];
        this.loading = false;
        this._items = [];
    }
    Object.defineProperty(TapConfigListComponent.prototype, "items", {
        set: /**
         * @param {?} items
         * @return {?}
         */
        function (items) {
            if (!items) {
                items = [];
            }
            items = items.map((/**
             * @param {?} item
             * @return {?}
             */
            function (item) {
                /** @type {?} */
                var defaultOption = defaultInfoResolverConfig.find((/**
                 * @param {?} defaultOption
                 * @return {?}
                 */
                function (defaultOption) { return item.key === defaultOption.key; }));
                if (defaultOption) {
                    item = __assign(__assign({}, defaultOption), item);
                }
                ;
                return item;
            }));
            this._items = items;
        },
        enumerable: true,
        configurable: true
    });
    ;
    /**
     * @return {?}
     */
    TapConfigListComponent.prototype.ngOnInit = /**
     * @return {?}
     */
    function () {
        var _this = this;
        this.sub = this.tapService
            .connectionState
            .subscribe((/**
         * @param {?} event
         * @return {?}
         */
        function (event) {
            var e_1, _a;
            switch (event.newState) {
                case ConnectionState.CONNECTED:
                    try {
                        for (var _b = __values(_this._items), _c = _b.next(); !_c.done; _c = _b.next()) {
                            var item = _c.value;
                            if (item.resolvedValue && item.resolvedValue.error && item.resolvedValue.error) {
                                // console.log(`Item ${item.key} has an error:`, item.resolvedValue.error);
                            }
                        }
                    }
                    catch (e_1_1) { e_1 = { error: e_1_1 }; }
                    finally {
                        try {
                            if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
                        }
                        finally { if (e_1) throw e_1.error; }
                    }
                    // 
                    break;
            }
        }));
    };
    /**
     * @return {?}
     */
    TapConfigListComponent.prototype.ngOnDestroy = /**
     * @return {?}
     */
    function () {
        this._items = [];
        if (this.sub) {
            this.sub.unsubscribe();
        }
    };
    /**
     * @return {?}
     */
    TapConfigListComponent.prototype.refresh = /**
     * @return {?}
     */
    function () {
        var _this = this;
        this.loading = true;
        this.tapService.infoResolver.refreshKeys(this._items.map((/**
         * @param {?} value
         * @return {?}
         */
        function (value) { return (/** @type {?} */ (value.key)); })))
            .finally((/**
         * @return {?}
         */
        function () { return _this.loading = false; }));
    };
    /**
     * @param {?} event
     * @return {?}
     */
    TapConfigListComponent.prototype.onSubmitValue = /**
     * @param {?} event
     * @return {?}
     */
    function (event) {
    };
    /**
     * @param {?} item
     * @param {?} action
     * @return {?}
     */
    TapConfigListComponent.prototype.clickAction = /**
     * @param {?} item
     * @param {?} action
     * @return {?}
     */
    function (item, action) {
        var _this = this;
        this.loading = true;
        action.call(this.tapService.tap)
            .then((/**
         * @param {?} response
         * @return {?}
         */
        function (response) {
            response.successful();
            if (action.triggersRefresh) {
                return _this.tapService.infoResolver.refreshKeys(action.triggersRefresh);
            }
        }))
            .catch((/**
         * @param {?} err
         * @return {?}
         */
        function (err) {
            _this.onError(err);
        }))
            .then((/**
         * @return {?}
         */
        function () {
            _this.loading = false;
        }));
    };
    /**
     * @param {?} err
     * @return {?}
     */
    TapConfigListComponent.prototype.onError = /**
     * @param {?} err
     * @return {?}
     */
    function (err) {
        return __awaiter(this, void 0, void 0, function () {
            var toast;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        console.warn(err);
                        return [4 /*yield*/, this.toastController.create({
                                message: err.message || 'Unknown error',
                                duration: 3000,
                                position: 'bottom'
                            })];
                    case 1:
                        toast = _a.sent();
                        toast.present();
                        return [2 /*return*/];
                }
            });
        });
    };
    /**
     * @return {?}
     */
    TapConfigListComponent.prototype.loadIfNeeded = /**
     * @return {?}
     */
    function () {
        console.log('TapConfigListComponent', 'load');
        this.tapService.infoResolver.loadKeysIfNotInCache(this._items.map((/**
         * @param {?} value
         * @return {?}
         */
        function (value) { return (/** @type {?} */ (value.key)); })));
    };
    /**
     * @param {?} item
     * @return {?}
     */
    TapConfigListComponent.prototype.isLoaded = /**
     * @param {?} item
     * @return {?}
     */
    function (item) {
        return this.tapService.infoResolver.isLoaded(item.key, this.params);
    };
    TapConfigListComponent.decorators = [
        { type: Component, args: [{
                    selector: 'tap-config-list',
                    template: "<ion-grid *ngIf=\"_items && _items.length > 0\" >\r\n    <ion-row *ngFor=\"let item of _items\" class=\"tap-config-row-{{item.key}}\">\r\n        <ion-col size-xs=\"12\"  size-sm=\"6\">\r\n            <ion-label>\r\n                <span  class=\"item-title\">{{item.title}}</span>\r\n                <ion-icon *ngIf=\"item.icon\" [name]=\"item.icon\"></ion-icon>\r\n                <br *ngIf=\"item.description\"/>\r\n                <span class=\"item-description\">{{item.description}}</span>\r\n            </ion-label>\r\n        </ion-col>\r\n        <ion-col size-xs=\"12\" size-sm=\"6\">\r\n            <tap-config-item *ngIf=\"!item.actions\" [info]=\"item\" [refresh]=\"itemRefresh\" [params]=\"params\"></tap-config-item>\r\n\r\n            <ion-buttons *ngIf=\"item.actions\">\r\n                <ion-button *ngFor=\"let action of item.actions\" [color]=\"action.color\" (click)=\"clickAction(item, action)\" [disabled]=\"loading\">\r\n                    <ion-icon *ngIf=\"action.icon\" [name]=\"action.icon\"></ion-icon>\r\n                    {{action.title}}\r\n                </ion-button>\r\n            </ion-buttons>\r\n        </ion-col>\r\n        <!-- <ion-spinner *ngIf=\"!isLoaded(item)\" slot=\"end\"></ion-spinner> -->\r\n    </ion-row>\r\n    <ion-toolbar *ngIf=\"globalRefresh\">\r\n        <ion-button [disabled]=\"loading\" float-right (click)=\"refresh()\" size=\"small\">\r\n            <ion-icon name=\"refresh\"></ion-icon>\r\n        </ion-button>\r\n    </ion-toolbar>\r\n</ion-grid>\r\n",
                    styles: ["table{width:100%}.item-description{font-size:.8em;color:#777}.item-title{color:#333;font-weight:700;font-size:1.05em}"]
                }] }
    ];
    /** @nocollapse */
    TapConfigListComponent.ctorParameters = function () { return [
        { type: CurrentDeviceService },
        { type: ToastController }
    ]; };
    TapConfigListComponent.propDecorators = {
        header: [{ type: Input }],
        globalRefresh: [{ type: Input }],
        itemRefresh: [{ type: Input }],
        lines: [{ type: Input }],
        columns: [{ type: Input }],
        params: [{ type: Input }],
        items: [{ type: Input }]
    };
    return TapConfigListComponent;
}());
if (false) {
    /** @type {?} */
    TapConfigListComponent.prototype.header;
    /** @type {?} */
    TapConfigListComponent.prototype.globalRefresh;
    /** @type {?} */
    TapConfigListComponent.prototype.itemRefresh;
    /** @type {?} */
    TapConfigListComponent.prototype.lines;
    /** @type {?} */
    TapConfigListComponent.prototype.columns;
    /** @type {?} */
    TapConfigListComponent.prototype.params;
    /** @type {?} */
    TapConfigListComponent.prototype.loading;
    /**
     * @type {?}
     * @private
     */
    TapConfigListComponent.prototype.sub;
    /** @type {?} */
    TapConfigListComponent.prototype._items;
    /**
     * @type {?}
     * @protected
     */
    TapConfigListComponent.prototype.tapService;
    /**
     * @type {?}
     * @protected
     */
    TapConfigListComponent.prototype.toastController;
    /* Skipping unhandled member: ;*/
}

/**
 * @fileoverview added by tsickle
 * Generated from: lib/tap-config.module.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var TapConfigModule = /** @class */ (function () {
    function TapConfigModule() {
    }
    TapConfigModule.decorators = [
        { type: NgModule, args: [{
                    declarations: [
                        TapConfigItemComponent,
                        TapConfigListComponent
                    ],
                    exports: [
                        TapConfigItemComponent,
                        TapConfigListComponent
                    ],
                    imports: [
                        LibCommonModule,
                        FormsModule,
                        ReactiveFormsModule
                    ]
                },] }
    ];
    return TapConfigModule;
}());

/**
 * @fileoverview added by tsickle
 * Generated from: lib/tap-config-parser.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
/**
 * @param {?} fileContent
 * @return {?}
 */
function parseTapConfiguratorConfig(fileContent) {
    if (isJsonString(fileContent)) {
        /** @type {?} */
        var config = JSON.parse(fileContent);
        // this.tapConfigPickerservice.onConfigSelected(config);
        return config;
    }
    else {
        // if (IotizeConfigFactory.fromXML(fileContent)) {
        return fromXml(fileContent);
    }
}
/**
 * @param {?} str
 * @return {?}
 */
function isJsonString(str) {
    try {
        /** @type {?} */
        var json = JSON.parse(str);
        return (typeof json === 'object');
    }
    catch (e) {
        return false;
    }
}
/**
 * @param {?} fileContent
 * @return {?}
 */
function fromXml(fileContent) {
    console.log('File content', fileContent);
    /** @type {?} */
    var parser = new DOMParser();
    /** @type {?} */
    var xmlConfig = parser.parseFromString(fileContent, 'application/xml');
    // let xmlConfig = parse(fileContent);
    /** @type {?} */
    var config = new IoTizeStudioToTapConfigConverter().convert(new DomElementAccessor((/** @type {?} */ (xmlConfig))));
    return { config: config };
}

/**
 * @fileoverview added by tsickle
 * Generated from: public_api.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */

/**
 * @fileoverview added by tsickle
 * Generated from: iotize-ionic-config.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */

export { TapConfigItemComponent, TapConfigListComponent, TapConfigModule, defaultInfoResolverConfig, fromXml, isJsonString, isTapConfigured, parseTapConfiguratorConfig };
//# sourceMappingURL=iotize-ionic-config.js.map
