//
//  CopyPasteButtonView.swift
//  PadelClub
//
//  Created by Razmig Sarkissian on 17/07/2024.
//

import SwiftUI

struct CopyPasteButtonView: View {
    var title: String?
    let pasteValue: String?
    @State private var copied: Bool = false
    
    @ViewBuilder
    var body: some View {
        if let pasteValue {
            Button {
                let pasteboard = UIPasteboard.general
                pasteboard.string = pasteValue
                copied = true
            } label: {
                Label(copied ? "Copié" : "Copier", systemImage: "doc.on.doc").symbolVariant(copied ? .fill : .none)
                if let title {
                    Text(title)
                }
            }
        }
    }
}

struct PasteButtonView: View {
    @Binding var text: String
    
    @ViewBuilder
    var body: some View {
        PasteButton(payloadType: String.self) { strings in
            if let pasteboard = strings.first {
                text = pasteboard
            }
        }
    }
}
