//
//  UserAvatarView.swift
//  demo
//
//  Created by Jason on 2024/1/25.
//

import SwiftUI

struct UserAvatarView: View {
    @Environment(\.presentationMode) private var presentationMode

    @State private var showSheet = false

    var body: some View {
        VStack {
            Image("Images/banner1")
                .resizable()
                .aspectRatio(contentMode: .fit)
                .frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.width)
        }
        .toolbar {
            ToolbarItem(placement: .navigationBarLeading) {
                Button {
                    presentationMode.wrappedValue.dismiss()
                } label: {
                    Image(systemName: "chevron.backward")
                }
            }

            ToolbarItem(placement: .navigationBarTrailing) {
                Button {
                    showSheet = true
                } label: {
                    Image(systemName: "ellipsis")
                }
                .actionSheet(isPresented: $showSheet, content: {
                    ActionSheet(title: Text("更换头像"), message: nil, buttons: [
                        .default(Text("从相册选择"), action: {}),
                        .default(Text("拍一张"), action: {}),
                        .cancel(Text("取消"))
                    ])
                })
            }
        }
        .navigationBarBackButtonHidden(true)
        .navigationBarTitleDisplayMode(.inline)
        .navigationTitle("头像")
    }
}

#Preview {
    UserAvatarView()
}
