import APIClient
import ComposableArchitecture
import Localization
import SwiftUI

public struct SongShareCardView: View {
    let clip: Clip
    @Shared var me: Me

    @State var downloadedImage: UIImage?

    public init(clip: Clip, me: Shared<Me>) {
        self.clip = clip
        self._me = me
    }

    public var body: some View {
        ShareCardView(
            .clip(clip),
            title: clip.title,
            tags: clip.tags,
            cta: cta,
            caption: caption,
            authorInfo:
            AuthorInfo(
                authorId: clip.userId,
                displayName: clip.displayName,
                imageUrl: clip.avatarImageUrl
            ),
            imageUrl: clip.largeImageUrl,
            fallbackId: clip.id.remoteId
        )
    }

    private var cta: String {
        if clip.userId == me.user.id {
            return L10n.FeatureShare.viewMySongsOnSuno
        } else {
            return L10n.FeatureShare.madeWithSuno
        }
    }

    private var caption: String? {
        return clip.userId == me.user.id ? L10n.FeatureShare.checkOutThisSong : nil
    }
}
