export function isOrderLocked(orderId?: string) {
  if (!orderId) return false
  try {
    const raw = localStorage.getItem('orderLocks')
    if (!raw) return false
    const map = JSON.parse(raw) as Record<string, boolean>
    return !!map[orderId]
  } catch {
    return false
  }
}

export function lockOrder(orderId?: string) {
  if (!orderId) return
  try {
    const raw = localStorage.getItem('orderLocks')
    const map = raw ? (JSON.parse(raw) as Record<string, boolean>) : {}
    map[orderId] = true
    localStorage.setItem('orderLocks', JSON.stringify(map))
  } catch {
    void 0
  }
}

export function clearOrderLock(orderId?: string) {
  if (!orderId) return
  try {
    const raw = localStorage.getItem('orderLocks')
    const map = raw ? (JSON.parse(raw) as Record<string, boolean>) : {}
    delete map[orderId]
    localStorage.setItem('orderLocks', JSON.stringify(map))
  } catch {
    void 0
  }
}