import SwiftUI struct AddTaskView: View { @Binding var isPresented: Bool @EnvironmentObject var authManager: AuthManager let onAdded: () async -> Void @State private var title = "" @State private var description = "" @State private var priority: Int = 2 @State private var isLoading = false private let priorities = [(1, "Низкий"), (2, "Средний"), (3, "Высокий"), (4, "Срочный")] var body: some View { NavigationView { ZStack { Color(hex: "0a0a1a").ignoresSafeArea() VStack(spacing: 20) { TextField("Название задачи", text: $title) .padding().background(Color.white.opacity(0.08)).cornerRadius(12).foregroundColor(.white) TextField("Описание (необязательно)", text: $description) .padding().background(Color.white.opacity(0.08)).cornerRadius(12).foregroundColor(.white) Picker("Приоритет", selection: $priority) { ForEach(priorities, id: \.0) { p in Text(p.1).tag(p.0) } } .pickerStyle(.segmented) Spacer() }.padding() } .navigationTitle("Новая задача") .navigationBarTitleDisplayMode(.inline) .toolbar { ToolbarItem(placement: .cancellationAction) { Button("Отмена") { isPresented = false } } ToolbarItem(placement: .confirmationAction) { Button("Добавить") { isLoading = true Task { let req = CreateTaskRequest( title: title, description: description.isEmpty ? nil : description, priority: priority ) try? await APIService.shared.createTask(token: authManager.token, request: req) await onAdded() await MainActor.run { isPresented = false } } } .disabled(title.isEmpty || isLoading) } } .preferredColorScheme(.dark) } } }