//
//  AppTab.swift
//  suixinkan
//

import UIKit

/// 主 Tab 实体，描述底部导航中的一级入口。
enum AppTab: String, CaseIterable, Hashable {
    case home
    case orders
    case statistics
    case profile

    var title: String {
        switch self {
        case .home: "首页"
        case .orders: "订单"
        case .statistics: "数据"
        case .profile: "我的"
        }
    }

    var selectedImageName: String {
        switch self {
        case .home: "tab_home_selected"
        case .orders: "tab_order_selected"
        case .statistics: "tab_data_selected"
        case .profile: "tab_profile_selected"
        }
    }

    var unselectedImageName: String {
        switch self {
        case .home: "tab_home_unselected"
        case .orders: "tab_order_unselected"
        case .statistics: "tab_data_unselected"
        case .profile: "tab_profile_unselected"
        }
    }

    /// 构建系统 TabBarItem。
    func makeTabBarItem() -> UITabBarItem {
        let unselectedImage = UIImage(named: unselectedImageName)?.withRenderingMode(.alwaysOriginal)
        let selectedImage = UIImage(named: selectedImageName)?.withRenderingMode(.alwaysOriginal)
        let item = UITabBarItem(title: title, image: unselectedImage, selectedImage: selectedImage)
        item.accessibilityIdentifier = "main.tab.\(rawValue)"
        return item
    }

    /// 构建 Tab 根页面。
    func makeRootViewController() -> UIViewController {
        switch self {
        case .home:
            return HomeViewController()
        case .orders:
            return OrdersViewController()
        case .statistics:
            return StatisticsViewController()
        case .profile:
            return ProfileViewController()
        }
    }
}
