package com.example.hmg_qline.hmg_qline

import android.content.Intent
import android.os.Bundle
import android.util.Log
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel

class MainActivity : FlutterActivity() {
    private val CHANNEL = "com.example.hmg_qline/foreground"

    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)

        MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result ->
            Log.d("MainActivity", "MethodChannel call received: ${call.method}")
            when (call.method) {
                "reopenApp" -> {
                    Log.d("MainActivity", "reopenApp called, bringing app to foreground")
                    // Simply bring current activity to foreground
                    moveTaskToBack(false)
                    // Or trigger Flutter navigation if needed
                    result.success("App brought to foreground")
                }

                else -> result.notImplemented()
            }
        }
    }
}
