//
//  LoadingViewModifier.swift
//  PadelClub
//
//  Created by Laurent Morvillier on 05/06/2024.
//

import Foundation
import SwiftUI

struct LoadingViewModifier: ViewModifier {
    
    let isLoading: Bool
    let tintColor: Color?

    func body(content: Content) -> some View {
        if self.isLoading {
            if let tintColor {
                ProgressView().tint(tintColor)
            } else {
                ProgressView()
            }
        } else {
            content
        }
    }
    
}

extension View {
    func isLoading(_ isLoading: Bool, tintColor: Color? = nil) -> some View {
        modifier(LoadingViewModifier(isLoading: isLoading, tintColor: tintColor))
    }
}
