struct ContentView: View {
   @State private var path = NavigationPath()
   @State private var picture: UIImage?
   @State private var showAlert: Bool = false

   var body: some View {
      NavigationStack(path: $path) {
         VStack {
            HStack {
               Button("Share Picture") {
                  showAlert = true
               }.buttonStyle(.glass)
               .disabled(picture == nil ? true : false)
               
               Spacer()
               NavigationLink(value: "Open Picker", label: {
                  Text("Get Picture")
               })
               .buttonStyle(.glassProminent)
               .padding()
               .navigationDestination(for: String.self) { _ in
                  ImagePicker { newpicture in
                     picture = newpicture
                     path.removeLast()
                  }
                  .ignoresSafeArea()
               }
               .alert("Save Picture", isPresented: $showAlert, actions: {
                  Button("Cancel", role: .cancel, action: {
                     showAlert = false
                  })
                  Button("YES", role: .none, action: {
                     if let picture {
                        UIImageWriteToSavedPhotosAlbum(picture, nil, nil, nil)
                     }
                  })
               }, message: { Text("Do you want to store the picture in the Photo Library?") })
            }
            Image(uiImage: picture ?? UIImage(named: "nopicture")!)
               .resizable()
               .scaledToFit()
            Spacer()
         }.padding()
      }.statusBarHidden()
   }
}