package prompt

import (
	"fmt"
	"strings"
)


const prompt_explain = 
`Your task is:
Explain the code.
Following the task requirements, explain the selected portion of the code. \
Note that you only explain the logic of the selected code. \
The visible code only serves as the context for you to understand the code. \
Here is the relevant context \
information for your reference:
1.  selected code info: {%s}
2.  current visible code info: {%s}
`

const prompt_explain_zh =
`你的任务是：
使用中文解释代码。
根据任务要求，解释被选中部分的代码。注意只解释被选中的代码逻辑，\
可见代码只是作为你理解代码的 context，你可以参考的 context 有：
1. 编辑器中被选中的代码：{%s}
2. 当前编辑器中可见代码：{%s}
`

func MakeExecExplain(lang, selected_text, visible_text string) string {
	var formatter string
	if lang == "zh" {
		formatter = prompt_explain_zh
	} else {
		formatter = prompt_explain
	}
	return fmt.Sprintf(formatter, selected_text, visible_text)
}


const ThinkStart = "<think>"
const ThinkEnd   = "</think>"

// remove <think> ... </think>
func RemoveThinkPart(m string) string {
	if strings.HasPrefix(m, ThinkStart) {
		if i := strings.LastIndex(m, ThinkEnd); i < 0 {
			return m
		} else {
			m = m[i+len(ThinkEnd):]
			return strings.TrimLeft(m, "\n")
		}
	} else {
		return m
	}
}

