import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("AuseftDDSPlugTest")

    property var currentPlugin: null

    ColumnLayout {
        anchors.centerIn: parent
        spacing: 20

        // Sample Machine Plugin
        Button {
            text: "Load Sample Machine Plugin"
            onClicked: {
                currentPlugin = pluginLoader.loadPlugin("/home/suzj/AuseftDDSPlugins/build/bin/AQTSampleMachinePlug.so")
                if (currentPlugin) {
                    if (currentPlugin.init()) {
                        statusText.text = "Sample Machine Plugin loaded"
                    } else {
                        statusText.text = "Failed to initialize Sample Machine Plugin"
                    }
                }
            }
        }

        // Package Machine Plugin
        Button {
            text: "Load Package Machine Plugin"
            onClicked: {
                currentPlugin = pluginLoader.loadPlugin("/home/suzj/AuseftDDSPlugins/build/bin/AQTPackageMachinePlug.so")
                if (currentPlugin) {
                    if (currentPlugin.init()) {
                        statusText.text = "Package Machine Plugin loaded"
                    } else {
                        statusText.text = "Failed to initialize Package Machine Plugin"
                    }
                }
            }
        }

        // Send Data Button
        Button {
            text: "Send Data"
            onClicked: {
                if (currentPlugin) {
                    currentPlugin.publishOnce()  // 调用当前插件的 publishOnce 方法
                } else {
                    statusText.text = "No plugin loaded"
                }
            }
        }

        // 显示状态信息
        Text {
            id: statusText
            text: "Ready"
            color: "black"
        }
    }

    // 处理插件加载错误
    Connections {
        target: pluginLoader
        function onMessagePublished(message, index) {
            statusText.text = "Message #" + index + ": " + message
        }
    }
}
