// // SidebarView.swift // MUA // // Created by Mitchel Volkering on 21/12/2025. // import SwiftUI enum NavigationItem: String, Identifiable, CaseIterable { case spaceLens = "Space Lens" case disks = "Disks" case largeFiles = "Large Files" case cleanup = "Cleanup" var id: String { rawValue } var icon: String { switch self { case .spaceLens: return "circle.hexagongrid.fill" case .disks: return "internaldrive.fill" case .largeFiles: return "doc.badge.arrow.up.fill" case .cleanup: return "trash.fill" } } var description: String { switch self { case .spaceLens: return "Visualize disk usage" case .disks: return "View connected drives" case .largeFiles: return "Find space hogs" case .cleanup: return "Clean unnecessary files" } } } struct SidebarView: View { @Binding var selectedItem: NavigationItem let disks: [DiskInfo] var body: some View { List(selection: $selectedItem) { Section("Analyze") { ForEach([NavigationItem.spaceLens, .largeFiles]) { item in NavigationLink(value: item) { Label(item.rawValue, systemImage: item.icon) } } } Section("Storage") { ForEach([NavigationItem.disks]) { item in NavigationLink(value: item) { Label(item.rawValue, systemImage: item.icon) } } // Quick disk overview ForEach(disks) { disk in DiskQuickView(disk: disk) } } Section("Maintain") { ForEach([NavigationItem.cleanup]) { item in NavigationLink(value: item) { Label(item.rawValue, systemImage: item.icon) } } } } .listStyle(.sidebar) .frame(minWidth: 200) } } struct DiskQuickView: View { let disk: DiskInfo var body: some View { VStack(alignment: .leading, spacing: 6) { HStack { Image(systemName: disk.icon) .foregroundStyle(.secondary) Text(disk.name) .font(.subheadline) } // Usage bar GeometryReader { geo in ZStack(alignment: .leading) { // Background RoundedRectangle(cornerRadius: 3) .fill(.quaternary) // Used space RoundedRectangle(cornerRadius: 3) .fill(usageColor) .frame(width: geo.size.width * CGFloat(disk.usedPercentage / 100)) } } .frame(height: 6) HStack { Text("\(disk.formattedFreeSpace) free") .font(.caption) .foregroundStyle(.secondary) Spacer() Text("of \(disk.formattedTotalSpace)") .font(.caption) .foregroundStyle(.tertiary) } } .padding(.vertical, 4) } private var usageColor: Color { let percentage = disk.usedPercentage if percentage > 90 { return .red } if percentage > 75 { return .orange } return .accentColor } } #Preview { SidebarView( selectedItem: .constant(.spaceLens), disks: [ DiskInfo( name: "Macintosh HD", mountPoint: URL(fileURLWithPath: "/"), totalSpace: 500_000_000_000, freeSpace: 120_000_000_000, isRemovable: false, isInternal: true ) ] ) .frame(width: 250, height: 400) }