//
//  TaskList.swift
//  Subtasks
//

import Adwaita

struct TaskList: View {

    @Binding var tasks: [Task]

    var view: Body {
        ScrollView {
            list
        }
        .topToolbar {
            HeaderBar.empty()
        }
    }

    var list: AnyView {
        List(tasks, selection: nil) { task in
            ActionRow()
                .title(task.label)
                .prefix {
                    CheckButton()
                        .active($tasks[id: task.id, default: .init(label: "")].done)
                        .selectionMode()
                        .valign(.center)
                }
                .suffix {
                    ButtonContent()
                        .iconName(Icon.default(icon: .goNext).string)
                }
        }
        .boxedList()
        .valign(.start)
        .padding(20)
        .frame(maxWidth: 500)
    }

}
