package mg.dot.feufaro.ui

import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.toComposeImageBitmap
import com.google.zxing.BarcodeFormat
import com.google.zxing.client.j2se.MatrixToImageWriter
import com.google.zxing.qrcode.QRCodeWriter

actual fun generateQRCode(content: String, size: Int): ImageBitmap? {
    return try {
        val writer = QRCodeWriter()
        val bitMatrix = writer.encode(content, BarcodeFormat.QR_CODE, size, size)

        val image = MatrixToImageWriter.toBufferedImage(bitMatrix)

        image.toComposeImageBitmap()

    } catch (e: Exception) {
        println("Erreur QR Code Desktop: ${e.message}")
        null
    }
}