import QtQuick
import QtQuick.Controls
import QtQuick.Controls.impl
import QtQuick.Layouts
import ISC
import ISC.Wafer

// Wafer overlap map card — renders per-sensor Run A/Run B temperature
// differences at the current scrub position.
PanelBox {
    id: card

    required property var sensorLayout
    required property var diffValues
    required property var diffBands      // function(values) -> band thresholds
    required property string waferShape
    required property real waferSize
    required property bool overlapEnabled
    required property real blendAmount   // 0–100, percent

    ColumnLayout {
        anchors.fill: parent
        anchors.margins: 12
        spacing: 8

        RowLayout {
            Layout.fillWidth: true
            SectionTitle {
                text: "WAFER OVERLAP"
                Layout.fillWidth: true
            }
        }

        Rectangle {
            Layout.fillWidth: true
            Layout.fillHeight: true
            color: Theme.fieldBackground
            border.color: Theme.cardBorder
            border.width: 1
            radius: Theme.radiusSm
            clip: true

            WaferMapItem {
                id: overlapMapItem
                anchors.fill: parent
                visible: card.sensorLayout.length > 0 && card.overlapEnabled
                sensors: card.sensorLayout
                values: card.diffValues
                bands: card.diffBands(overlapMapItem.values)
                shape: card.waferShape
                size: card.waferSize
                target: 0
                margin: 1.0
                blend: card.blendAmount / 100
                showLabels: true
                showExtremes: false
                ringColor: Theme.waferRingColor
                axisColor: Theme.waferAxisColor
                lowColor: Theme.sensorLow
                inRangeColor: Theme.sensorInRange
                highColor: Theme.sensorHigh
                textColor: Theme.headingColor
            }

            ColumnLayout {
                anchors.centerIn: parent
                visible: card.sensorLayout.length === 0 || !card.overlapEnabled
                spacing: 4
                IconImage {
                    Layout.alignment: Qt.AlignHCenter
                    source: "../icons/map.svg"
                    width: 24; height: 24
                    sourceSize.width: 24
                    sourceSize.height: 24
                    color: Theme.sideMutedText
                }
                Label {
                    Layout.alignment: Qt.AlignHCenter
                    text: !card.overlapEnabled ? "Overlap map disabled"
                        : "No sensor map available"
                    color: Theme.bodyColor
                    font.pixelSize: Theme.fontXs
                }
            }
        }
    }
}
