import SwiftUI
import SFSafeSymbols

struct FileToAddView: View {

    @ObservedObject
    var file: FileToAdd

    let delete: (FileToAdd) -> Void

    var body: some View {
        VStack(alignment: .leading) {
            HStack {
                Image(systemSymbol: file.isSelected ? .checkmarkCircleFill : .circle)
                    .resizable()
                    .frame(width: 20, height: 20)
                    .foregroundStyle(.blue)
                    .onTapGesture {
                        file.isSelected.toggle()
                    }
                Image(systemSymbol: .trashCircleFill)
                    .resizable()
                    .frame(width: 20, height: 20)
                    .foregroundStyle(.red)
                    .onTapGesture {
                        delete(file)
                    }
                TextField("", text: $file.uniqueId)
                    .textFieldStyle(.roundedBorder)
                    .frame(maxWidth: 200)

            }
            Text(file.url?.path() ?? "Placeholder file")
                .foregroundStyle(.secondary)
        }

    }
}

#Preview {
    List {
        FileToAddView(file: .init(content: .mock, url: URL(fileURLWithPath: "/path/to/file.swift")), delete: { _ in })
        FileToAddView(file: .init(content: .mock, url: URL(fileURLWithPath: "/path/to/file2.swift")), delete: { _ in })
    }
}
