//
//  GameView.swift
//  Zockerhoehle
//
//  Created by Julian-Steffen Müller on 25.05.21.
//  Copyright © 2021 Julian-Steffen Müller. All rights reserved.
//

import Foundation
import SwiftUI

struct GameView : View {
    @ObservedObject var game : Game
    
    let defaultImage = UIImage()
    
    var body: some View {
        if ICloudManager.fileExists(at: game.cover_icloud_path) {
            Image(uiImage: ICloudManager.imageFrom(path: game.cover_icloud_path) ?? defaultImage)
                .resizable()
                .scaledToFit()
                .cornerRadius(5)
        }else{
            Group {
                Text(game.name)
                    .font(.caption)
                    .foregroundColor(Color.black)
                    .padding()
                    .multilineTextAlignment(.center)
            }
            .frame(maxWidth: .infinity, maxHeight: .infinity)
            .background(Color.gray)
            .cornerRadius(5)
        }
    }
}
