//
//  ListRowViewModifier.swift
//  PadelClub
//
//  Created by Razmig Sarkissian on 27/03/2024.
//

import SwiftUI

struct ListRowViewModifier: ViewModifier {
    let isActive: Bool
    let color: Color
    var hideColorVariation: Bool = false
    
    func colorVariation() -> Color {
        hideColorVariation ? Color(uiColor: .systemBackground) : color.variation()
    }

    func body(content: Content) -> some View {
        if isActive {
            content
                .listRowBackground(
                    colorVariation()
                        .overlay(alignment: .leading, content: {
                            color.frame(width: 8)
                        })
                )
        } else {
            content
        }
    }
}

extension View {
    func listRowView(isActive: Bool = false, color: Color, hideColorVariation: Bool = false) -> some View {
        modifier(ListRowViewModifier(isActive: isActive, color: color, hideColorVariation: hideColorVariation))
    }
}
