//
//  ProfileImage.swift
//  SimpleX
//
//  Created by Evgeny on 23/03/2022.
//  Copyright © 2022 SimpleX Chat. All rights reserved.
//

import SwiftUI
import SimpleXChat

struct ProfileImage: View {
    var imageStr: String? = nil
    var iconName: String = "person.crop.circle.fill"
    var color = Color(uiColor: .tertiarySystemGroupedBackground)
    
    var body: some View {
        if let image = imageStr,
           let data = Data(base64Encoded: dropImagePrefix(image)),
           let uiImage = UIImage(data: data) {
            Image(uiImage: uiImage)
                .resizable()
                .clipShape(Circle())
        } else {
            Image(systemName: iconName)
                .resizable()
                .foregroundColor(color)
        }
    }
}

struct ProfileImage_Previews: PreviewProvider {
    static var previews: some View {
        ProfileImage(imageStr: "data:image/png;base64,[encoded data, 4192 characters]")
            .previewLayout(.fixed(width: 63, height: 63))
            .background(.black)
    }
}
