//
//  TSKeyboardView.swift
//  AIEmoji
//
//  Created by 100Years on 2025/1/21.
//

import SwiftUI
import Combine
struct TSKeyboardView : View {
    
    var keyBoardModelArray:[[DiyStickerModel]]
    let clickKeyPublisher:PassthroughSubject<DiyStickerModel, Never>
    var body: some View {
        let itemW = (k_ScreenWidth - 56)/10.0
        return VStack {
    
            Spacer().frame(height: 12)

            VStack(spacing:12) {
                ForEach(keyBoardModelArray, id: \.self) { array in
                    HStack(spacing:5) {
                        ForEach(array, id: \.self.name) { model in
                            
                            if model.name == kKeyDelete {
                                TSKeyboardDeleteView(model: model).frame(width:itemW)
                                .onTapGesture {
                                    clickKeyPublisher.send(model)
                                }
                            }else{
                                TSKeyboardItemView(model: model).frame(width:itemW)
                                .onTapGesture {
                                    clickKeyPublisher.send(model)
                                }
                            }
 
                        }
                    }
                }
            }
            
            Spacer().frame(height: 8 + k_Height_safeAreaInsetsBottom())
        }
    }
}


struct TSKeyboardItemView : View {
    var model:DiyStickerModel
    var body: some View {
        return VStack {
            VStack(spacing: 0) {
                Spacer().frame(height: 4)
            
                Image(model.imageUrl ?? "").resizable().frame(width: 24, height: 24)

                HStack {
                    Spacer()
                    Text(model.name ?? "?").foregroundColor(.black).font(.font(size: 12)).frame(height: 12)
                    Spacer().frame(width: 2)
                }

                Spacer().frame(height: 2)
            }
            .background("#F1F4F8".uiColor.color)
            .cornerRadius(5)
            .shadow(color: .black.opacity(0.2), radius: 2, x: 0, y: 2) // 设置阴影
            
        }
    }
}


struct TSKeyboardDeleteView : View {
    var model:DiyStickerModel
    var body: some View {
        return HStack {
            Spacer().frame(width: 14).background(Color.red)
            VStack {
                Image(model.imageUrl ?? "").resizable().frame(width: 23, height: 17)
            }
            .frame(width: 42,height: 42)
            .background("#F1F4F8".uiColor.color)
            .cornerRadius(5)
            .shadow(color: .black.opacity(0.2), radius: 2, x: 0, y: 2) // 设置阴影
        }
    }
}

