import BackendEnvironmentClient
import Foundation
import SwiftUI

public enum DebugMenuPanelType: String, Equatable, Identifiable, CaseIterable {
    case panelSelector

    case trackedMetrics
    case featureToggles
    case internalViews
    case reportBug
    case appSessions
    case appStorage
    case environment

    case flex

    /// This is when you view one specific file - like a JSON/text file, from within the `onDeviceFileExplorer` view
    case fileViewerPanel
    /// This is the file tree
    case onDeviceFileExplorer

    public var id: String { self.rawValue }

    static var selectableTypes: [DebugMenuPanelType] {
        allCases.filter(\.showAtRoot)
    }

    var showAtRoot: Bool {
        switch self {
        case .panelSelector, .fileViewerPanel:
            false

        case .flex:
            #if DEBUG
                true
            #else
                /// FLEX has to be excluded from non debug builds. see Build Settings > Build Options > Excluded Source File Names
                false
            #endif

        case .environment:
            BackendEnvironmentProvider.isStaffBuild()

        default:
            true
        }
    }

    var showsPanelSelector: Bool {
        !showAtRoot
    }

    var displayTitle: String {
        switch self {
        case .trackedMetrics:
            "Metrics"
        case .appSessions:
            "App Sessions"
        case .featureToggles:
            "Feature Toggles"
        case .onDeviceFileExplorer:
            "File Explorer"
        case .fileViewerPanel:
            "File Viewer Panel"
        case .internalViews:
            "Internal Views"
        case .reportBug:
            "Report Bug"
        case .panelSelector:
            ""
        case .flex:
            "FLEX"
        case .appStorage:
            "App Storage"
        case .environment:
            "Environment"
        }
    }

    var iconName: String {
        switch self {
        case .trackedMetrics:
            "chart.dots.scatter"
        case .appSessions:
            "clock.badge.checkmark"
        case .featureToggles:
            "switch.2"
        case .panelSelector:
            "square"
        case .onDeviceFileExplorer:
            "folder"
        case .internalViews:
            "arrowshape.turn.up.right.circle"
        case .reportBug:
            "exclamationmark.triangle"
        case .fileViewerPanel:
            "doc"
        case .flex:
            "arrowshape.turn.up.right.circle"
        case .appStorage:
            "internaldrive"
        case .environment:
            "network"
        }
    }

    var iconColor: Color {
        switch self {
        case .trackedMetrics:
            return .green
        case .appSessions:
            return .purple
        case .featureToggles:
            return .blue
        case .onDeviceFileExplorer:
            return .yellow
        case .internalViews:
            return .orange
        case .reportBug:
            return .red
        case .panelSelector:
            return .white
        case .fileViewerPanel:
            return .orange
        case .flex:
            return .gray
        case .appStorage:
            return .cyan
        case .environment:
            return .mint
        }
    }
}
