// QmsPlugin.mm
#import "QmsPlugin.h"
#import "DashboardViewController.h"
#import "DrawerViewController.h"
#import "DrawerController.h"
#import "NetworkManager.h"
#import "UnitViewController.h"
#import "ProjectViewController.h"

@implementation QmsPluginUI

+ (UIViewController *)makeViewController {
    [NetworkManager sharedManager];

    // 1️⃣ Drawer menu
    DrawerViewController *drawer = [[DrawerViewController alloc] init];
    drawer.profileName = @"placeholder";
    drawer.profileEmail = @"placeholder";

    // 2️⃣ Screens
    ProjectViewController *project = [[ProjectViewController alloc] init]; // Landing page
    UnitViewController *unit = [[UnitViewController alloc] init];         // Secondary page
    DashboardViewController *dashboard = [[DashboardViewController alloc] init];

    // 3️⃣ UINavigationController with landing page
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:project];

    // 4️⃣ Create drawer controller wrapping nav
    NSString *clientID = @"clientID_loading";
    NSString *clientCode = @"clientCode_loading";
    NSString *userToken = @"userToken_loading";

    DrawerController *drawerController = [[DrawerController alloc]
        initWithDrawerViewController:drawer
                            clientID:clientID
                          clientCode:clientCode
                           userToken:userToken];

    // 5️⃣ Assign main content (nav) to drawerController
    [drawerController setValue:nav forKey:@"_mainVC"];

    // 6️⃣ Inject drawerController reference into all screens
    project.drawerController = drawerController;
    unit.drawerController = drawerController;
    dashboard.drawerController = drawerController;

    return drawerController;
}

@end
