You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.3 KiB
72 lines
2.3 KiB
//
|
|
// ParticipateButton.swift
|
|
// AllIn
|
|
//
|
|
// Created by Lucas Delanier on 15/01/2024.
|
|
//
|
|
|
|
import SwiftUI
|
|
import Model
|
|
|
|
struct ParticipateButton: View {
|
|
|
|
@Binding var isOpen : Bool
|
|
@Binding var isParticapatedOpen: Bool
|
|
var bet: Bet?
|
|
|
|
var isDisabled: Bool {
|
|
guard let endRegisterDate = bet?.endRegisterDate else {
|
|
return true
|
|
}
|
|
|
|
let currentDate = Date()
|
|
|
|
switch currentDate.compare(endRegisterDate) {
|
|
case .orderedAscending:
|
|
return false
|
|
case .orderedDescending, .orderedSame:
|
|
return true
|
|
}
|
|
}
|
|
|
|
var body: some View {
|
|
Button {
|
|
isOpen = true
|
|
isParticapatedOpen = true
|
|
} label: {
|
|
Text("Participer")
|
|
.font(.system(size: 27))
|
|
.fontWeight(.semibold)
|
|
.frame(maxWidth: .infinity).padding(10)
|
|
.multilineTextAlignment(.center)
|
|
.overlay {
|
|
switch isDisabled {
|
|
case true:
|
|
AllInColors.grey700Color.frame(width: 170)
|
|
.mask(
|
|
Text("Participer")
|
|
.font(.system(size: 27))
|
|
.fontWeight(.semibold)
|
|
.frame(maxWidth: .infinity).padding(10)
|
|
)
|
|
case false:
|
|
AllInColors.primaryGradient.frame(width: 170)
|
|
.mask(
|
|
Text("Participer")
|
|
.font(.system(size: 27))
|
|
.fontWeight(.semibold)
|
|
.frame(maxWidth: .infinity).padding(10)
|
|
)
|
|
|
|
}
|
|
}
|
|
.accentColor(AllInColors.componentBackgroundColor)
|
|
.background(isDisabled ? AllInColors.delimiterGrey.opacity(0.5):AllInColors.whiteColor)
|
|
.buttonStyle(.borderedProminent).cornerRadius(4.0)
|
|
.overlay(
|
|
RoundedRectangle(cornerRadius: 12).stroke(AllInColors.delimiterGrey, lineWidth: 1)
|
|
)
|
|
}.disabled(isDisabled)
|
|
}
|
|
}
|