aboutsummaryrefslogtreecommitdiff
path: root/foray/Scenes/ForayDetailViewController.swift
blob: 24de38f88d19c3f0b6f79e9d34fc75968d6213fa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
//  ForayDetailViewController.swift
//  foray
//
//  Created by Nicholas Tay on 16/3/2022.
//

import UIKit

class ForayDetailViewController: UIViewController, HasCustomView, Coordinated {
    
    typealias CustomView = ForayDetailView
    typealias CoordinatorType = ForayCoordinator
    
    var coordinator: ForayCoordinator?
    private var item: PenguinItemViewModel?

    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "Details"

        customView.onAction = { [weak self] (action) in
            guard let self = self, let item = self.item else { return }
            switch action {
            case .onShare:
                self.coordinator?.share(item: item)
            }
        }
    }
    
    override func loadView() {
        view = ForayDetailView()
    }
    
    public func setDetails(item: PenguinItemViewModel) {
        self.item = item
        let image: UIImage
        var description: String = "Type: "
        switch item.type {
        case .item:
            description += "Item"
            image = UIImage(named: item.id) ?? UIImage.fromAsset(.it)
        case .quest:
            description += "Quest"
            image = UIImage.fromAsset(.spy)
        }
        description += "\nID: " + item.id
        description += "\nReleased: " + item.releaseDateFormatted
        
        self.customView.setDetails(name: item.name, description: description, image: image)
    }

}