//
//  SelectPlayerButtonView.swift
//  DouShouQi_App
//
//  Created by etudiant on 23/05/2024.
//

import SwiftUI

struct CustomShapeLeftButton: Shape {
    func path(in rect: CGRect) -> Path {
        var path = Path()
        path.move(to: CGPoint(x: rect.minX, y: rect.minY)) // coin supérieur gauche
        path.addLine(to: CGPoint(x: rect.maxX - 60, y: rect.minY)) // un peu avant le coin supérieur droit
        path.addLine(to: CGPoint(x: rect.maxX, y: rect.minY + 60)) // un peu en dessous du coin supérieur droit
        path.addLine(to: CGPoint(x: rect.maxX, y: rect.maxY)) // coin inférieur droit
        path.addLine(to: CGPoint(x: rect.minX, y: rect.maxY)) // coin inférieur gauche
        path.closeSubpath()
        return path
    }
}

struct CustomShapeRightButton: Shape {
    func path(in rect: CGRect) -> Path {
        var path = Path()
        path.move(to: CGPoint(x: rect.minX + 60, y: rect.minY)) // un peu à droite du coin supérieur gauche
        path.addLine(to: CGPoint(x: rect.maxX, y: rect.minY)) // coin supérieur droit
        path.addLine(to: CGPoint(x: rect.maxX, y: rect.maxY)) // coin inférieur droit
        path.addLine(to: CGPoint(x: rect.minX, y: rect.maxY)) // coin inférieur gauche
        path.addLine(to: CGPoint(x: rect.minX, y: rect.minY + 60)) // un peu en dessous du coin supérieur gauche
        path.closeSubpath()
        return path
    }
}


struct SelectPlayerButtonView: View {
    var player1:String = "IA"
    var player2:String = "IA"
    var body: some View {
        ZStack{
            Image("vs-custom")
               .resizable()
               .aspectRatio(contentMode: .fit)
               .frame(width: 100, height: 100)
               .offset(y: -60)
            HStack{
                VStack (alignment: .leading) {
                    Text(player1)
                        .font(.title)
                        .padding(3)
                    Button(action: {
                        print("Button j1 pressé!")
                    }) {
                        VStack {
                            Text("+")
                                .font(.largeTitle)
                                .bold()
                            Text("Add a player")
                                .font(.body)
                                .bold()
                        }
                        .frame(width: 150, height: 150)
                        .padding()
                        .border(/*@START_MENU_TOKEN@*/Color.black/*@END_MENU_TOKEN@*/, width: 4)
                        .foregroundColor(.black)
                        .foregroundColor(.white)
                        .cornerRadius(10)
                        .clipShape(CustomShapeLeftButton())
                    }
                }
                VStack (alignment: .trailing) {
                    Text(player2)
                        .font(.title)
                        .padding(3)
                    
                    Button(action: {
                        print("Button j2 pressé!")
                    }) {
                        VStack {
                            Text("+")
                                .font(.largeTitle)
                                .bold()
                            Text("Add a player")
                                .font(.body)
                                .bold()
                        }                            .frame(width: 150, height: 150)
                        .padding()
                        .foregroundColor(.black)
                        .border(/*@START_MENU_TOKEN@*/Color.black/*@END_MENU_TOKEN@*/, width: 4)
                        .foregroundColor(.white)
                        .cornerRadius(10)
                        .clipShape(CustomShapeRightButton())
                    }
                }
            }
        }
    }
}

struct SelectPlayerButtonView_Previews: PreviewProvider {
    static var previews: some View {
        SelectPlayerButtonView()
    }
}
