53 lines
1.9 KiB
Go
53 lines
1.9 KiB
Go
package keyboard
|
||
|
||
import (
|
||
"bitrix_balancer_api/core/utilscore"
|
||
"bitrix_balancer_api/telegram_service/state"
|
||
"fmt"
|
||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||
)
|
||
|
||
// BuildFileInputKeyboard строит клавиатуру с кнопками открепления каждого файла,
|
||
// кнопкой отправки (с количеством) и кнопкой отправки без файлов.
|
||
// keyboard/file_input.go
|
||
func BuildFileInputKeyboard(topicCode string, files []state.FileAttachment) tgbotapi.InlineKeyboardMarkup {
|
||
var rows [][]tgbotapi.InlineKeyboardButton
|
||
|
||
// Кнопка «Открепить» для каждого файла
|
||
for i, f := range files {
|
||
label := []rune(f.FileName)
|
||
if len(label) > 25 {
|
||
label = append(label[:22], []rune("...")...)
|
||
}
|
||
rows = append(rows, tgbotapi.NewInlineKeyboardRow(
|
||
tgbotapi.NewInlineKeyboardButtonData(
|
||
"🗑 "+string(label),
|
||
fmt.Sprintf("appr_file_detach:%d", i),
|
||
),
|
||
))
|
||
}
|
||
|
||
// Кнопка отправки — показывает количество файлов
|
||
submitLabel := "✅ Отправить на согласование"
|
||
if n := len(files); n > 0 {
|
||
submitLabel = fmt.Sprintf("✅ Отправить (%s)", utilscore.PluralFiles(n))
|
||
}
|
||
rows = append(rows, tgbotapi.NewInlineKeyboardRow(
|
||
tgbotapi.NewInlineKeyboardButtonData(submitLabel, "appr_file_submit:"+topicCode),
|
||
))
|
||
|
||
// Кнопка «без файлов» появляется только если уже что-то прикреплено
|
||
if len(files) > 0 {
|
||
rows = append(rows, tgbotapi.NewInlineKeyboardRow(
|
||
tgbotapi.NewInlineKeyboardButtonData("📤 Отправить без файлов", "appr_file_skip:"+topicCode),
|
||
))
|
||
}
|
||
|
||
// Кнопка «Назад» — всегда внизу
|
||
rows = append(rows, tgbotapi.NewInlineKeyboardRow(
|
||
tgbotapi.NewInlineKeyboardButtonData("← Назад", "appr_back:"+topicCode),
|
||
))
|
||
|
||
return tgbotapi.NewInlineKeyboardMarkup(rows...)
|
||
}
|