package alraune

import alraune.operations.*
import pieces100.*
import vgrechka.*
import java.io.File

class RP_Debug_PageBecameStale : RemoteProcedureBase<RP_Debug_PageBecameStale.Params>(RP_Debug_PageBecameStale.Params::class) {
    class Params {
        var initialContent by notNullOnce<String>()
        var currentContent by notNullOnce<String>()
    }

    override fun dance() {
        checkIsLocalDebug_elseBitch()
        rctx0.al.suspiciouslyLargeXStreamedServantsAllowed = true

        clog("--- initialContent = ${args.initialContent.substring(0, 50)}")
        clog("--- currentContent = ${args.currentContent.substring(0, 50)}")
        // 9d5550db-2fdb-4c90-a04c-67937b9b6c8d
        val button = button().id(nextJsIdent()).add("Staleness diff")
        btfEval("""
            ${'$'}(document.body).append(${jsStringLiteral(button.render())})
            ${jsOnDomidClick_prevent(button.attrs.id, jsCallBackendServantHandle(freakingServant(::serveStalenessDiffButtonClick)))}
        """)
    }

    fun serveStalenessDiffButtonClick() {
        fun fart(content: String): String {
            val file = AlDebug.tempFile(uuid())
            stripIgnoredStuffForPageSha1ing(content) pipe TextPile::prettyPrintHtml pipe {file.writeText(it)}
            return file.path
        }

        btfEval("console.log('So, you are now stale, little motherfucker?')")
        runLocalMergeTool_noBlock(fart(args.initialContent), fart(args.currentContent))
    }

    object Test1 {
        @JvmStatic fun main(args: Array<String>) {
            if (isWindowsOS())
                runLocalMergeTool_noBlock(
                    "C:\\Program Files (x86)\\WinMerge\\Contributors.txt",
                    "C:\\Program Files (x86)\\WinMerge\\Files.txt")
            else
                runLocalMergeTool_noBlock(
                    "/home/into/pro/febig/fe-private/alraune-private/src-for-alraune/alraune/operations/AlCtl_BackShitUp.kt",
                    "/home/into/pro/febig/fe-private/alraune-private/src-for-alraune/alraune/operations/AlCtl_BackShitUp_Obsolete.kt")
        }
    }

    object Test2 {
        @JvmStatic fun main(args: Array<String>) {
            val untidy = File("c:\\tmp\\alraune\\cd84aa22-37c1-4b38-8e5a-20a9d0946677").readText()
            val tidy = TextPile.prettyPrintHtml(untidy)
            clog(tidy)
        }
    }
}
















