// // MainCoordinator.swift // SUIExamples // // Created by Pavel Yurchenko on 28.11.2024. // import CoordinatorSUI import SwiftUI final class MainCoordinator: BaseCoordinator { init(router: Router) { super.init() self.currentRouter = router } func run() -> some View { showMainModule() } @ViewBuilder func buildDestination(_ route: Route) -> some View { switch route { case .products: showProductsModule() case .product(let id): showProductModule(with: id) case .cart: showCartModule() default: EmptyView() } } // MARK: - Private methods private func showMainModule() -> some View { MainBuilder().build( with: .init( onProducts: { [weak self] in self?.currentRouter.push(Route.products) }, onProduct: { [weak self] id in self?.currentRouter.push(Route.product(id: id)) }, onCart: { [weak self] in self?.currentRouter.push(Route.cart) } ) ) } private func showProductsModule() -> some View { ProductsBuilder().build( with: .init( onProduct: { [weak self] in self?.currentRouter.push(Route.product(id: $0)) }, onCart: { [weak self] in self?.currentRouter.push(Route.cart) } ) ) } private func showCartModule() -> some View { CartBuilder().build( with: .init( onProducts: { [weak self] in self?.currentRouter.push(Route.products) } ) ) } private func showProductModule(with id: Int) -> some View { ProductBuilder().build( with: .init(id: id), output: .init( onProducts: { [weak self] in self?.currentRouter.push(Route.products) }, onCart: { [weak self] in self?.currentRouter.push(Route.cart) } ) ) } }