//
//  NavButton.swift
//  DouShouQiIOS
//
//  Created by Mathilde Jean on 31/05/2024.
//

import SwiftUI

struct NavButton<D1:View>: View {
    
    let text : String
    let destinationView : () -> D1
    let hideBackButton : Bool
    
    init(_ text : String, @ViewBuilder destinationView: @escaping () -> D1, hideBackButton : Bool = false) {
        self.text = text
        self.destinationView = destinationView
        self.hideBackButton = hideBackButton
    }
    
    var body: some View {
        NavigationLink(destination: destinationView().navigationBarBackButtonHidden(hideBackButton))
        {
            Text("\(text)")
                .font(.title2)
                .padding()
                .background(Color.primaryColor)
                .foregroundColor(.white)
                .cornerRadius(8)
        }
    }
}

struct NavButton_Previews: PreviewProvider {
    
    static var previews: some View {
        NavButton("Menu princ", destinationView: {MainMenuView()})
    }
}
