import AnalyticsClient
import APIClient
import AVFoundation
import ComponentLibrary
import ComposableArchitecture
import FeatureClipDetail
import SwiftUI

public struct ExpandedPlayerPlayPauseButton: View {
    private enum Constants {
        static let buttonSize: CGFloat = 70
        static let iconSize: CGFloat = 40
    }

    let playTapped: () -> Void
    let pauseTapped: () -> Void
    let timeControlStatus: AVPlayer.TimeControlStatus

    @Dependency(AnalyticsClient.self) var analyticsClient

    public var body: some View {
        Button {
            switch timeControlStatus {
            case .paused:
                playTapped()
            case .waitingToPlayAtSpecifiedRate:
                pauseTapped()
            case .playing:
                pauseTapped()
            @unknown default:
                break
            }
        } label: {
            ZStack {
                if timeControlStatus == .paused {
                    Image.Omniplayer.playCircleCutout
                        .resizable()
                        .frame(width: Constants.buttonSize, height: Constants.buttonSize)
                } else {
                    Image.Omniplayer.pauseCircleCutout
                        .resizable()
                        .frame(width: Constants.buttonSize, height: Constants.buttonSize)
                }
            }
        }
        .frame(width: Constants.buttonSize, height: Constants.buttonSize)
        .buttonStyle(ScaleButtonStyle(scaleAmount: 0.9))
    }
}
