package com.fabledsword.minstrel.shared.widgets.trackactions

import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import com.composables.icons.lucide.EllipsisVertical
import com.composables.icons.lucide.Lucide
import com.fabledsword.minstrel.models.TrackRef

/**
 * Small kebab IconButton that opens [TrackActionsSheet] for [track].
 * Drop into any track row alongside (or in place of) a LikeButton.
 *
 * [hideQueueActions] suppresses Play next + Add to queue — set true
 * on the NowPlaying caller where the menu's track IS the playing one.
 * [onNavigateToAlbum] / [onNavigateToArtist] are invoked AFTER the
 * sheet has dismissed, so callers that live on a full-screen overlay
 * (e.g. NowPlaying) can pop themselves first inside the callback.
 */
@Composable
fun TrackActionsButton(
    track: TrackRef,
    hideQueueActions: Boolean = false,
    onNavigateToAlbum: (albumId: String) -> Unit,
    onNavigateToArtist: (artistId: String) -> Unit,
) {
    var show by remember { mutableStateOf(false) }
    IconButton(onClick = { show = true }) {
        Icon(
            imageVector = Lucide.EllipsisVertical,
            contentDescription = "Track actions",
            tint = MaterialTheme.colorScheme.onSurfaceVariant,
        )
    }
    if (show) {
        TrackActionsSheet(
            track = track,
            hideQueueActions = hideQueueActions,
            onDismiss = { show = false },
            onNavigateToAlbum = onNavigateToAlbum,
            onNavigateToArtist = onNavigateToArtist,
        )
    }
}
