"use strict";
var __assign = (this && this.__assign) || Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
        s = arguments[i];
        for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
            t[p] = s[p];
    }
    return t;
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
            t[p[i]] = s[p[i]];
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
var filter = require("lodash/filter");
var React = require("react");
var recompose_1 = require("recompose");
var ResinDeviceStatus = require("resin-device-status");
var styled_components_1 = require("styled-components");
var Gauge_1 = require("./Gauge");
var asRendition_1 = require("../asRendition");
var theme_1 = require("../theme");
var colors = theme_1.default.colors;
var pathFillColor = function (status) {
    if (status === 'idle') {
        return colors.statusIdle.main;
    }
    if (status === 'configuring') {
        return colors.statusConfiguring.main;
    }
    if (status === 'updating') {
        return colors.statusUpdating.main;
    }
    if (status === 'post-provisioning') {
        return colors.statusPostProvisioning.main;
    }
    if (status === 'offline') {
        return colors.statusOffline.main;
    }
};
var DeviceStatusGauge = function (_a) {
    var devices = _a.devices, props = __rest(_a, ["devices"]);
    var data = [];
    var allDevices = devices || [];
    ResinDeviceStatus.statuses.forEach(function (status) {
        var devices = filter(allDevices, function (d) { return ResinDeviceStatus.getStatus(d).key === status.key; });
        data.push({
            key: status.key,
            name: status.name,
            value: devices.length,
            color: pathFillColor(status.key),
        });
    });
    return (React.createElement(Gauge_1.default, __assign({}, props, { data: data, title: "Total Devices", placeholderColor: colors.statusOffline.main })));
};
exports.default = recompose_1.compose(styled_components_1.withTheme, asRendition_1.default)(DeviceStatusGauge);
