import SwiftUI

struct CustomTabBar: View {
    @Binding var selectedTab: Int
    var onCreate: () -> Void

    var body: some View {
        HStack {
            // Tab 1: Feed
            TabBarButton(systemName: "list.bullet.rectangle", text: "Лента", isSelected: selectedTab == 0) {
                selectedTab = 0
            }

            // Tab 2: Search
            TabBarButton(systemName: "magnifyingglass", text: "Поиск", isSelected: selectedTab == 1) {
                selectedTab = 1
            }

            // Create Button
            CreateButton {
                onCreate()
            }

            // Tab 3: Chats
            TabBarButton(systemName: "bubble.left.and.bubble.right.fill", text: "Чаты", isSelected: selectedTab == 2) {
                selectedTab = 2
            }

            // Tab 4: Profile
            TabBarButton(systemName: "person.crop.square", text: "Лицо", isSelected: selectedTab == 3) {
                selectedTab = 3
            }
        }
        .padding(.horizontal)
        .padding(.top, 1)
        .padding(.bottom, 18) // Добавляем отступ снизу
        .background(Color(.systemGray6))
    }
}

struct TabBarButton: View {
    let systemName: String
    let text: String
    let isSelected: Bool
    let action: () -> Void

    var body: some View {
        Button(action: action) {
            VStack(spacing: 4) {
                Image(systemName: systemName)
                    .font(.system(size: 22))
                Text(text)
//                    .font(.caption)
                    .font(.system(size: 12))
            }
            .foregroundColor(isSelected ? .accentColor : .gray)
        }
        .frame(maxWidth: .infinity)
    }
}

struct CreateButton: View {
    let action: () -> Void

    var body: some View {
        Button(action: action) {
            Image(systemName: "plus")
                .font(.system(size: 24, weight: .bold))
                .foregroundColor(.white)
                .padding(16)
//                .background(Color.accentColor)
                .background(
                    LinearGradient(
                        gradient: Gradient(colors: [.blue, .white]),
                        startPoint: .top,
                        endPoint: .bottom
                    )
                )
                .clipShape(Circle())
                .shadow(radius: 4)
        }
        .offset(y: -3)
    }
}
