// File: util/Extensions.kt
package com.example.notesai.util

import androidx.compose.ui.graphics.Color

// String Extensions
fun String.truncate(maxLength: Int, suffix: String = "..."): String {
    return if (this.length > maxLength) {
        this.substring(0, maxLength) + suffix
    } else {
        this
    }
}

// Color Extensions
fun Long.toColor(): Color = Color(this)

fun Color.withAlpha(alpha: Float): Color = this.copy(alpha = alpha)

// List Extensions
fun <T> List<T>.replaceWhere(predicate: (T) -> Boolean, transform: (T) -> T): List<T> {
    return this.map { if (predicate(it)) transform(it) else it }
}

fun <T> List<T>.removeWhere(predicate: (T) -> Boolean): List<T> {
    return this.filter { !predicate(it) }
}

fun <T> List<T>.updateWhere(predicate: (T) -> Boolean, transform: (T) -> T): List<T> {
    return this.map { if (predicate(it)) transform(it) else it }
}