import QtQuick
import QtQuick.Layouts

import "../views"

DockablePanelWindow {
    id: root

    property var trendController: null
    property bool independentMetricSelection: false
    property bool panelLockButtonVisible: true
    property alias localSelectedMetricKey: trendsView.localSelectedMetricKey

    signal additionalWindowRequested(string metricKey)

    width: 1050
    height: 620
    minimumWidth: 360
    minimumHeight: 220
    panelTitle: "Мастер-значения"
    panelCounterText: root.trendController
                      ? root.trendController.statusMessage
                      : "Мастер-значения недоступны"
    title: root.independentMetricSelection
           && trendsView.activeMetricName.length > 0
           ? trendsView.activeMetricName + " — Мастер-значения — VibroExplorer"
           : "Мастер-значения — VibroExplorer"

    function openTrends() {
        openPanel()
    }

    function openTrendsAtCurrentPosition() {
        systemWindowMode = true
        showWithCurrentGeometry(true)
        raise()
        requestActivate()
    }

    function openTrendsForDrag(globalX, globalY,
                               pressOffsetX, pressOffsetY) {
        openPanelForDrag(globalX, globalY,
                         pressOffsetX, pressOffsetY)
    }

    TrendsWorkspaceView {
        id: trendsView

        Layout.fillWidth: true
        Layout.fillHeight: true
        Layout.minimumWidth: 0
        Layout.minimumHeight: 0
        trendController: root.visible ? root.trendController : null
        independentMetricSelection: root.independentMetricSelection
        locked: root.locked
        lockButtonVisible: root.systemWindowMode
                           && root.panelLockButtonVisible
        onLockToggled: function(locked) { root.lockToggled(locked) }
        onAdditionalWindowRequested: function(metricKey) {
            root.additionalWindowRequested(metricKey)
        }
    }
}
