import QtQuick 2.0
import QtQuick.Layouts 1.12
import LibreHub 1.0

ColumnLayout {
  id: notifictaion_column
  spacing: 10;

  Connections {
    target: API;
    function onRecivedError(err) { createNotifiction("Error", err); }
  }

  function createNotifiction(title, data) {
    let component = Qt.createComponent("NotificationComponent.qml");
    const finishHandler = ()=>{
      if (component.status === Component.Ready) {
        let sprite = component.createObject(notifictaion_column, {notification_title: title, notification_text: data});
        if (sprite === null) {
          // Error Handling
          console.log(`${title}:${data}`);
          console.log("Creating notifiction component error!");
        }
      } else if (component.status === Component.Error) {
        // Error Handling
        console.log("Error loading component:", component.errorString());
      }
    }
    if (component.status === Component.Ready)
            finishHandler();
        else
            component.statusChanged.connect(finishHandler);
  }
}
