struct ContentView: View {
   @Environment(ApplicationData.self) private var appData

   let guides = [
      GridItem(.adaptive(minimum: 75))
   ]
   var body: some View {
      ScrollView {
         LazyVGrid(columns: guides) {
            ForEach(appData.userData) { book in
               Image(book.cover)
                  .resizable()
                  .scaledToFit()
            }
            .reorderable()
         }
         .reorderContainer(for: Book.self, move: { diff in
             guard let sourceIndex = appData.userData.firstIndex(where: { $0.id == diff.sources[0] }) else { return }
             let element = appData.userData.remove(at: sourceIndex)
             
             var destinationIndex: Int?
             switch diff.destination.position {
             case .end:
                 destinationIndex = appData.userData.endIndex
             case .before(let id):
                 destinationIndex = appData.userData.firstIndex(where: { $0.id == id })
             }
             if let destinationIndex {
                 appData.userData.insert(element, at: destinationIndex)
             }
         })
      }.padding()
   }
}