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 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import React, { forwardRef } from 'react';
import { makeStyles, Typography, useTheme, Divider, Box } from '@material-ui/core';
import { MuiVegaLite } from '@material-vega/material-ui';
import { Sparklines, SparklinesLine } from 'react-sparklines';
import WidgetCard from '../../WidgetCard';
import FluentStatNumber from '../../FluentComponents/molecules/FluentStatNumber';
import { convertISODate } from '../../utils/ConvertISODate';
export const layout = {
    w: { default: 2, min: 0, max: 4 },
    h: { default: 2, min: 0, max: 4 }
};
// export const params = {
//   mode: {
//     defaultValue: 'chart',
//   },
// };
const useStyles = makeStyles((theme) => ({
    displayItems: {
        display: 'flex',
        flexDirection: 'row',
        width: '100%'
    },
    visualCaption: {
        marginTop: theme.spacing(-1)
    },
    lineGraph: {
        width: '100%',
        '& svg': { width: '100%' }
    }
}));
const LineAndSparklinesWidget = (props, ref) => {
    const { children, params, setParam } = props, other = __rest(props, ["children", "params", "setParam"]);
    const { mockData, apiUrl, theme, dateRange } = params;
    const classes = useStyles();
    const mainTheme = useTheme();
    return (React.createElement(WidgetCard, Object.assign({ ref: ref, title: mockData === null || mockData === void 0 ? void 0 : mockData.title, theme: theme }, other), mockData ? (React.createElement("div", null, dateRange && (React.createElement(Typography, { gutterBottom: true, variant: "caption", component: "h3" }, "From: ", convertISODate(dateRange.from), " to:", ' ', convertISODate(dateRange.to))), React.createElement("div", { className: classes.displayItems }, React.createElement("div", null, React.createElement(FluentStatNumber, { number: mockData === null || mockData === void 0 ? void 0 : mockData.value, trend: "up" })), React.createElement("div", { style: { width: '100%' } }, React.createElement(Sparklines, { data: mockData === null || mockData === void 0 ? void 0 : mockData.sparklinesData, strokeWidth: 1, style: { width: '100%', height: 45, marginTop: 10 } }, React.createElement(SparklinesLine, { color: mainTheme.palette.secondary.main })), React.createElement("div", { className: classes.visualCaption }, React.createElement("div", null, React.createElement(Divider, null)), React.createElement(Typography, { variant: "caption" }, mockData === null || mockData === void 0 ? void 0 : mockData.label)))), React.createElement(Box, { clone: true, flex: 1, mt: 1, overflow: "hidden" }, React.createElement(MuiVegaLite, { variant: "areaLineChart", style: {
            width: '100%'
        }, spec: {
            $schema: 'https://vega.github.io/schema/vega-lite/v4.json',
            height: 150,
            data: { values: mockData === null || mockData === void 0 ? void 0 : mockData.data },
            mark: 'area',
            encoding: {
                x: {
                    field: 'xAxis',
                    type: mockData === null || mockData === void 0 ? void 0 : mockData.xAxisType
                },
                y: {
                    aggregate: 'sum',
                    field: 'yAxis',
                    type: mockData === null || mockData === void 0 ? void 0 : mockData.yAxisType,
                    scale: { domain: (mockData === null || mockData === void 0 ? void 0 : mockData.domain) || '' }
                }
            }
        }, autoResize: "true", width: "container" })), children)) : (React.createElement(Typography, { variant: "subtitle2" }, "Could not retrieve widget data. Please contact support"))));
};
export default forwardRef(LineAndSparklinesWidget);
//# sourceMappingURL=LineAndSparklinesWidget.js.map