import QtQuick
import QtQuick.Layouts
import ISC
import ISC.Tabs.components

// ===== Graph Tab =====
// Whole-run multi-sensor line chart (C# parity: tabGraph/chartData). Static
// snapshot recomputed whenever a file is loaded — not live-updating during
// a stream. RunChart adds wheel zoom, drag pan, and a visible-range
// min/max/avg strip. See specs/plans/2026-07-10-graph-tab.md and
// docs/adr/0003-pyqtgraph-for-multi-sensor-charts.md.
Item {
    id: root
    anchors.fill: parent

    function refresh() {
        if (!streamController.loadedFile) {
            chart.seriesData = []
            chart.sensorNames = []
            return
        }
        chart.sensorNames = streamController.graphSensorNames
            ? streamController.graphSensorNames.split(",") : []
        chart.seriesData = JSON.parse(streamController.graphSeriesJson || "[]")
    }

    Connections {
        target: streamController
        function onLoadedFileChanged() { root.refresh() }
    }

    Component.onCompleted: root.refresh()

    Rectangle {
        anchors.fill: parent
        anchors.margins: Theme.panelPadding
        color: Theme.cardBackground
        border.color: Theme.cardBorder
        border.width: 1
        radius: Theme.radiusMd

        RunChart {
            id: chart
            anchors.fill: parent
            anchors.margins: 8
            title: "Sensor Temperature Over Time"
        }
    }
}
