//
//  InputUserNameView.swift
//  forShip
//
//  Created by Mamoru Sugita on 2023/10/13.
//

import SwiftUI

struct InputUserNameView: View {
    @Binding var isLogin: Bool
    @EnvironmentObject var loginViewParam: LoginViewParam
    let itemHPadding: Double = 16
    let dialogBottomPadding: Double = 32
    let textFieldHeight: Double = 40
    let inputAreaHeight: Double = 150
    let dialogHeight: CGFloat = 250
    let dialogWidth = UIScreen.main.bounds.width - 32
    var body: some View {
        
    
        HStack {
            Spacer()
                .frame(width: itemHPadding)
            VStack{
                Spacer()
                
                VStack(alignment: .leading) {
                    Text("JRC Ship")
                        .padding(.leading, 4)
                        .bold()
                        .foregroundColor(.white)
                                        
                    HStack{
                        Image("account")
                            .padding(.horizontal, 4)
                            .foregroundColor(.white)
                        TextField(
                            "",
                            text: $loginViewParam.userName,
                            prompt: Text("Please set user name")
                            .foregroundColor(.white)
                        )
                        .frame(height: textFieldHeight)
                        .padding(.trailing)
                        .foregroundColor(.white)
                    }
                    
                    Divider()
                        .frame(height: 2)
                        .background(Color(.white))
                }
                .frame(height: inputAreaHeight)
                
                
                
                Spacer()
                    
                Button(action: {
                    // TODO: API通信 ログイン認証処理
                    isLogin = true
                    Preferences.lastLoginDate_Int64 = DateTextLib.Date2UnixTime(date: Date())
                    
                    
                }, label: {
                    Text("Sign In")
                        .frame(height: 50)
                        .frame(maxWidth: .infinity)
                        .foregroundColor(ColorSet.ButtonText.color)
                        .background(ColorSet.PrimaryActiveIcon.color)
                })
                
                Spacer()
                    .frame(height: dialogBottomPadding)
            }
            
            Spacer()
                .frame(width: itemHPadding)
        }
        .frame(width: dialogWidth, height: dialogHeight)
        .background(ColorSet.BackgroundSecondary.color)
    }
}

#Preview {
    InputUserNameView(isLogin: .constant(false))
}
