import SwiftUI

@Observable class ApplicationData {
   @ObservationIgnored let center = NotificationCenter.default
   var scrollOffset: CGFloat = 0

   static let shared: ApplicationData = ApplicationData()
   private init() {
      Task {
         await receiveNotificationOpen()
      }
      Task {
         await receiveNotificationClose()
      }
   }
   func receiveNotificationOpen() async {
      let name = UIWindow.keyboardDidShowNotification
      for await _ in center.notifications(named: name, object: nil) {
         await MainActor.run {
            scrollOffset = -20
         }
      }
   }
   func receiveNotificationClose() async {
      let name = UIWindow.keyboardDidHideNotification
      for await _ in center.notifications(named: name, object: nil) {
         await MainActor.run {
            scrollOffset = 0
         }
      }
   }
}