package options

// func GetDefaultExport(filePath, fileName string) string {
// 	bundle := parseJSWithESBuild(filePath)
// 	return stringifyJSObject(bundle, fileNameToVar(fileName))
// }

// func parseJSWithESBuild(filePath string) string {
// 	result := api.Build(api.BuildOptions{
// 		Format:            api.FormatESModule,
// 		EntryPoints:       []string{filePath},
// 		Bundle:            true,
// 		MinifyWhitespace:  false,
// 		MinifyIdentifiers: false,
// 		MinifySyntax:      false,
// 		Engines: []api.Engine{
// 			{Name: api.EngineChrome, Version: "101"},
// 		},
// 	})
// 	if len(result.Errors) > 0 {
// 		log.Fatalf("Failed to compile %s\n%v\n", filePath, result.Errors)
// 	}

// 	return string(result.OutputFiles[0].Contents)
// }

// func stringifyJSObject(bundle, objVar string) string {
// 	fc := string(bundle)

// 	parseExport := false
// 	str := ""
// 	ekw := "export"

// 	for i := 0; i < len(fc); i++ {
// 		if parseExport {
// 			if fc[i] == ';' {
// 				parseExport = false
// 			}
// 			continue
// 		}

// 		if fc[i] == 'e' && fc[i:len(ekw)+i] == ekw {
// 			parseExport = true
// 			i += len(ekw)
// 			continue
// 		}

// 		str += string(fc[i])
// 	}

// 	scriptsStr := str + "scripts=JSON.stringify(" + objVar + ")" + "\n" + "scripts"

// 	return v8isolates(scriptsStr)
// }

// func fileNameToVar(fileName string) string {
// 	fnVar := ""
// 	for i := 0; i < len(fileName)-3; i++ {
// 		switch fileName[i] {
// 		case '.':
// 			fnVar += "_"
// 			continue
// 		}
// 		fnVar += string(fileName[i])
// 	}
// 	return fnVar + "_default"
// }

// func v8isolates(script string, isolateOpt ...*v8.Isolate) string {
// 	var isolate *v8.Isolate
// 	if len(isolateOpt) > 0 {
// 		isolate = isolateOpt[0]
// 	}

// 	ctx := v8.NewContext(isolate)
// 	defer ctx.Close()

// 	output, e := ctx.RunScript(script, "function.js")
// 	if e != nil {
// 		log.Fatalf("Error: %+v\n", e)
// 	}

// 	return output.String()
// }
