//
//  StepsPage.swift
//  Project
//
//  Created by Kara Graysen on 2021-08-28.
//

import SwiftUI

struct StepsPage: View {
    @State var job: ProjectQuery.CheckSuite.Node.WorkflowRun.CheckSuite.CheckRun.Node
    var steps: [ProjectQuery.CheckSuite.Node.WorkflowRun.CheckSuite.CheckRun.Node.Step.Node] {
        guard let nodes = job.steps?.nodes else {
            return []
        }
        
        return nodes.compactMap { $0 }
    }
    
    var body: some View {
        List(steps) { step in
            let conclusion = step.conclusion?.rawValue.lowercased().capitalizingFirstLetter() ?? Constants.error
            let description = "\(conclusion) \(Constants.stepsIn) \(String(describing: step.secondsToCompletion ?? -1)) \(Constants.stepsSeconds)"
            Row(title: step.name, description: description)
        }.navigationTitle(job.name)
    }
}
