//
//  AnimeView.swift
//  Macondo
//
//  Created by Louis Shen on 2021/1/2.
//

import Foundation
import SwiftUI

struct AnimeView : View {
    @EnvironmentObject var showView : ViewNavigation
    var ads : [AnimeData] = [AnimeData]()
    var lang : String
    
    init(language : String) {
        ads = Sqlite.getAnimeList(language: language)
        lang = language
    }
    
    var body : some View {
        NavigationView {
            List(ads, id: \.self) { (ad)  in
                NavigationLink(destination: EditAnimeView(aid: ad.getAid(), language: self.lang)) {
                    Text(ad.getNameZH())
                }
            }
            .listStyle(InsetListStyle())
            .frame(minWidth: 280, idealWidth: 280, maxWidth: 350, maxHeight: .infinity)
        }
        .toolbar {
            Button(action: {
                Sqlite.newTempAnime(language: self.showView.lang)
                self.showView.showView = 4
            }) {
                Image(systemName: "square.and.pencil")
                .help("Create a new anime collection")
            }
        }
    }
}
