//
//  VIew+.swift
//  Toolboxes
//
//  Created by 研发2组 on 2024/9/29.
//

import SwiftUI

struct GradientView: View {
    
    var colors: [Color]  = [.customgradient_top, .customgradient_bottom]
    
    var startPoint: UnitPoint = .top
    var endPoint: UnitPoint = .bottom
    
    var body: some View {
        LinearGradient(gradient: Gradient(colors: colors), startPoint: startPoint, endPoint: endPoint)
            .ignoresSafeArea()
    }
}

struct CircularBackgroundModifier: ViewModifier {
    
    var size: CGFloat

    func body(content: Content) -> some View {
        content
        .frame(width: size * 0.7, height: size * 0.7)
        .background(
            Circle()
                .fill(Color.white)
                .frame(width: size, height: size)
        )
        .shadow(color: Color.customshadow, radius: 10, x: 0, y: 5)
    }
}

struct CircularWhiteBackgroundModifier: ViewModifier {
    
    var size: CGFloat

    func body(content: Content) -> some View {
        content
            .frame(width: size * 0.7, height: size * 0.7)
            .background(
                Circle()
                .fill(Color.white)
                .frame(width: size, height: size)
            )
    }
}


extension View {
    
    func circularBackground(size: CGFloat) -> some View {
        self.modifier(CircularBackgroundModifier(size: size))
    }
    
    func circularwhiteBackground(size: CGFloat) -> some View {
        self.modifier(CircularWhiteBackgroundModifier(size: size))
    }
    
    func gradientBackground(colors: [Color] = [Color.white, Color.customWhite]) -> some View {
           self.background(
               LinearGradient(
                   gradient: Gradient(colors: colors),
                   startPoint: .top,
                   endPoint: .bottom
               )
           )
       }
}
