// A segmented choice that is NOT schema-bound.
//
// ChoiceRow reads its options from the preference schema. This one is handed
// them, for choices that describe system state rather than a Panama setting.

import QtQuick
import qs.config

SettingRow {
    id: root

    // [{ value, label }]
    property var options: []
    property var value: null
    property bool enabled: true

    signal selected(value: var)

    controlWidth: Math.max(150, root.options.length * 92)

    Row {
        anchors.right: parent.right
        anchors.verticalCenter: parent.verticalCenter
        spacing: 6
        opacity: root.enabled ? 1 : 0.45

        Repeater {
            model: root.options

            delegate: Rectangle {
                id: segment

                required property var modelData

                readonly property bool current: root.value === segment.modelData.value

                width: Math.max(84, segmentLabel.implicitWidth + 22)
                height: 30
                radius: 9
                color: segment.current
                    ? Theme.alpha(Theme.accent, 0.22)
                    : Theme.alpha(Theme.fg, segmentMouse.containsMouse ? 0.12 : 0.06)
                border.width: 1
                border.color: segment.current
                    ? Theme.alpha(Theme.accent, 0.5)
                    : Theme.alpha(Theme.fg, 0.08)

                Text {
                    id: segmentLabel
                    anchors.centerIn: parent
                    text: String(segment.modelData.label ?? "")
                    color: segment.current ? Theme.fg : Theme.fgDim
                    font.family: Theme.fontFamily
                    font.pixelSize: Theme.fontSizeSmall
                    font.weight: segment.current ? Font.DemiBold : Font.Medium
                }

                MouseArea {
                    id: segmentMouse
                    anchors.fill: parent
                    hoverEnabled: true
                    enabled: root.enabled && !segment.current
                    cursorShape: Qt.PointingHandCursor
                    onClicked: root.selected(segment.modelData.value)
                }
            }
        }
    }
}
