96 lines
2.8 KiB
Go
96 lines
2.8 KiB
Go
package keyboard
|
||
|
||
import (
|
||
"bitrix_balancer_api/telegram_service/approvalflow"
|
||
"fmt"
|
||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||
)
|
||
|
||
// BuildApprovalStep строит обычные кнопки выбора (без мультиселекта).
|
||
// allowedTopicCodes — список кодов тем, на которые у пользователя есть права.
|
||
// Если nil — фильтрация не применяется.
|
||
//func BuildApprovalStep(
|
||
// topicCode string,
|
||
// nodes []*approvalflow.FlowNode,
|
||
// allowedTopicCodes map[string]bool, // nil = без фильтрации
|
||
//) tgbotapi.InlineKeyboardMarkup {
|
||
// var rows [][]tgbotapi.InlineKeyboardButton
|
||
//
|
||
// for _, n := range nodes {
|
||
// if n == nil {
|
||
// continue
|
||
// }
|
||
// // Проверяем право доступа если задан TopicCode узла
|
||
// if n.TopicCode != "" && allowedTopicCodes != nil {
|
||
// if !allowedTopicCodes[n.TopicCode] {
|
||
// continue
|
||
// }
|
||
// }
|
||
//
|
||
// rows = append(rows, tgbotapi.NewInlineKeyboardRow(
|
||
// tgbotapi.NewInlineKeyboardButtonData(
|
||
// n.Label,
|
||
// fmt.Sprintf("appr:%s:%s", topicCode, n.Key),
|
||
// ),
|
||
// ))
|
||
// }
|
||
//
|
||
// rows = append(rows, tgbotapi.NewInlineKeyboardRow(
|
||
// tgbotapi.NewInlineKeyboardButtonData("← Назад", fmt.Sprintf("appr_back:%s", topicCode)),
|
||
// ))
|
||
//
|
||
// return tgbotapi.NewInlineKeyboardMarkup(rows...)
|
||
//}
|
||
|
||
// BuildMultiSelectStep строит кнопки мультиселекта с чекбоксами.
|
||
func BuildMultiSelectStep(
|
||
topicCode string,
|
||
nodes []*approvalflow.FlowNode,
|
||
selectedValues []string,
|
||
allowedTopicCodes map[string]bool,
|
||
) tgbotapi.InlineKeyboardMarkup {
|
||
selectedSet := make(map[string]bool, len(selectedValues))
|
||
for _, v := range selectedValues {
|
||
selectedSet[v] = true
|
||
}
|
||
|
||
var rows [][]tgbotapi.InlineKeyboardButton
|
||
|
||
for _, n := range nodes {
|
||
if n == nil {
|
||
continue
|
||
}
|
||
if n.TopicCode != "" && allowedTopicCodes != nil {
|
||
if !allowedTopicCodes[n.TopicCode] {
|
||
continue
|
||
}
|
||
}
|
||
|
||
label := n.Label
|
||
if selectedSet[n.MultiSelectValue] {
|
||
label = "✅ " + label
|
||
}
|
||
|
||
rows = append(rows, tgbotapi.NewInlineKeyboardRow(
|
||
tgbotapi.NewInlineKeyboardButtonData(
|
||
label,
|
||
fmt.Sprintf("appr_ms_toggle:%s:%s:%s", topicCode, n.Key, n.MultiSelectValue),
|
||
),
|
||
))
|
||
}
|
||
|
||
// Кнопка подтверждения
|
||
confirmLabel := "✅ Подтвердить"
|
||
if len(selectedValues) > 0 {
|
||
confirmLabel = fmt.Sprintf("✅ Подтвердить (%d)", len(selectedValues))
|
||
}
|
||
rows = append(rows, tgbotapi.NewInlineKeyboardRow(
|
||
tgbotapi.NewInlineKeyboardButtonData(confirmLabel, fmt.Sprintf("appr_ms_confirm:%s", topicCode)),
|
||
))
|
||
rows = append(rows, tgbotapi.NewInlineKeyboardRow(
|
||
tgbotapi.NewInlineKeyboardButtonData("← Назад", fmt.Sprintf("appr_back:%s", topicCode)),
|
||
))
|
||
|
||
return tgbotapi.NewInlineKeyboardMarkup(rows...)
|
||
}
|