import Quickshell.Services.Pipewire
import QtQuick

import qs.config
import qs.services

Column {
    id: root

    property var applications: AudioDevices.applications
    property bool pipewireReady: Pipewire.ready

    readonly property int rowCount: applicationRepeater.count
    readonly property string statusText: {
        if (!root.pipewireReady)
            return "PipeWire is unavailable";
        if (root.applications.length === 0)
            return "Applications playing sound will appear here";
        return "";
    }

    width: parent ? parent.width : 620
    spacing: 8

    Repeater {
        id: applicationRepeater
        model: root.applications

        ApplicationVolumeRow {
            required property var modelData

            width: root.width
            application: modelData
        }
    }

    Text {
        width: parent.width
        visible: root.statusText !== ""
        text: root.statusText
        color: Theme.fgDim
        font.family: Theme.fontFamily
        font.pixelSize: Theme.fontSize
        horizontalAlignment: Text.AlignHCenter
        topPadding: 18
        bottomPadding: 18
    }
}
