package login_js

import (
	"fmt"

	"github.com/robertkrimen/otto"
)

func Js(fn string, args ...any) any {
	vm := otto.New()
	fullCode := jsCrypto + LoginJs
	value, err := vm.Run(fullCode)
	if err != nil {
		fmt.Println("执行JavaScript代码时出错:", err.Error())
	}

	value, err = vm.Call(fn, nil, args...)
	if err != nil {
		fmt.Println("执行JavaScript代码时出错:", err.Error())
	}
	res, _ := value.Export()
	return res
}

func Test2(fn string) any {
	vm := otto.New()
	//fullCode := jsCrypto + Test
	value, err := vm.Run(Test1)
	if err != nil {
		fmt.Println("执行JavaScript代码时出错1:", err.Error())
	}

	value, err = vm.Call(fn, nil)
	if err != nil {
		fmt.Println("执行JavaScript代码时出错2:", err.Error())
	}
	res, _ := value.Export()
	return res
}
