import APIClient
import ComponentLibrary
import ComposableArchitecture
import Utilities

extension CommentsSheetReducer {
    /// The user might want to send the comment for a specific part in the track,
    /// but by the time they finish typing, that part of the track might have past.
    /// Lock the track timestamp when a specific condition is met.
    func lockTrackTimeIfNeeded(state: inout State, when shouldLock: Bool) {
        guard state.item.commentEntityType == .clip else { return }
        if shouldLock, state.lockedTrackTime == nil {
            state.lockedTrackTime = state.elapsedTrackTime
        }
    }

    func unlockTrackTimeIfNeeded(state: inout State, when shouldUnlock: Bool) {
        guard state.item.commentEntityType == .clip else { return }
        if shouldUnlock, state.lockedTrackTime != nil {
            state.lockedTrackTime = nil
        }
    }
}
