package keyboard import ( "bitrix_balancer_api/core/lib/external/tgkit" "bitrix_balancer_api/core/typescore" "bitrix_balancer_api/telegram_service/approvalflow" "fmt" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" ) // ── Выбор согласующего ────────────────────────────────────────── func BuildApproverSelectionMenu(approvers []*typescore.User, page int) interface{} { const perPage = 8 total := len(approvers) totalPages := (total + perPage - 1) / perPage if page < 0 { page = 0 } if page >= totalPages && totalPages > 0 { page = totalPages - 1 } start, end := page*perPage, page*perPage+perPage if end > total { end = total } kb := tgkit.NewInlineKeyboard() for _, a := range approvers[start:end] { if a.ID == nil || a.FullName == nil { continue } kb.Row(tgkit.Btn(*a.FullName, fmt.Sprintf("select_approver:%d", *a.ID))) } if totalPages > 1 { kb.Rows = append(kb.Rows, buildPageRow(page, totalPages, "select_approver_page", "select_approver_noop")) } return kb.Build() } func BuildFirstApproverSelectionMenu(users []*typescore.User, page int) tgbotapi.InlineKeyboardMarkup { const perPage = 8 total := len(users) totalPages := (total + perPage - 1) / perPage if page < 0 { page = 0 } if page >= totalPages && totalPages > 0 { page = totalPages - 1 } start := page * perPage end := start + perPage if end > total { end = total } kb := tgkit.NewInlineKeyboard() for _, u := range users[start:end] { if u.ID == nil || u.FullName == nil { continue } kb.Row(tgkit.Btn(*u.FullName, fmt.Sprintf("first_approver_select:%d", *u.ID))) } if totalPages > 1 { kb.Rows = append(kb.Rows, buildPageRow(page, totalPages, "first_approver_page", "first_approver_noop")) } return kb.Build() } func BuildObserverSelectionMenu(observers []*typescore.User, selectedIDs []uint64, page int, isRequired bool) tgbotapi.InlineKeyboardMarkup { const perPage = 8 if len(observers) == 0 { kb := tgkit.NewInlineKeyboard() if isRequired { kb.Row(tgkit.Btn("⚠️ Нет доступных наблюдателей", "obs_select_noop")) } else { kb.Row(tgkit.Btn("✅ Подтвердить без наблюдателей", "obs_select_confirm")) } return kb.Build() } total := len(observers) totalPages := (total + perPage - 1) / perPage if page < 0 { page = 0 } if page >= totalPages { page = totalPages - 1 } start := page * perPage end := start + perPage if end > total { end = total } selected := make(map[uint64]bool, len(selectedIDs)) for _, id := range selectedIDs { selected[id] = true } kb := tgkit.NewInlineKeyboard() for _, u := range observers[start:end] { if u.ID == nil || u.FullName == nil { continue } label := *u.FullName if selected[*u.ID] { label = "✅ " + label } kb.Row(tgkit.Btn(label, fmt.Sprintf("obs_select_toggle:%d", *u.ID))) } if totalPages > 1 { kb.Rows = append(kb.Rows, buildPageRow(page, totalPages, "obs_select_page", "obs_select_noop")) } if isRequired { if len(selectedIDs) == 0 { kb.Row(tgkit.Btn("⚠️ Выберите хотя бы одного наблюдателя", "obs_select_confirm")) } else { kb.Row(tgkit.Btn( fmt.Sprintf("✅ Подтвердить (%d выбрано)", len(selectedIDs)), "obs_select_confirm", )) } } else { confirmLabel := "✅ Подтвердить" if len(selectedIDs) > 0 { confirmLabel = fmt.Sprintf("✅ Подтвердить (%d выбрано)", len(selectedIDs)) } else { confirmLabel = "✅ Подтвердить без наблюдателей" } kb.Row(tgkit.Btn(confirmLabel, "obs_select_confirm")) } return kb.Build() } func BuildObserverTopicMenu(topics []approvalflow.Topic, page int) tgbotapi.InlineKeyboardMarkup { const perPage = 6 total := len(topics) totalPages := (total + perPage - 1) / perPage if page < 0 { page = 0 } if page >= totalPages && totalPages > 0 { page = totalPages - 1 } start := page * perPage end := start + perPage if end > total { end = total } var rows [][]tgbotapi.InlineKeyboardButton for _, t := range topics[start:end] { rows = append(rows, tgbotapi.NewInlineKeyboardRow( tgbotapi.NewInlineKeyboardButtonData(t.Name(), fmt.Sprintf("obs_topic:%s", t.Code())), )) } if totalPages > 1 { rows = append(rows, tgkit.PaginationRow( page, totalPages, fmt.Sprintf("obs_topic_page:%d", page-1), fmt.Sprintf("obs_topic_page:%d", page+1), "obs_topic_noop", )) } return tgbotapi.NewInlineKeyboardMarkup(rows...) } func BuildObserverApprovalList(approvals []*typescore.Approval, initiators map[uint64]*typescore.User, departments map[uint64]*typescore.Department) interface{} { kb := tgkit.NewInlineKeyboard() for _, a := range approvals { if a.ID == nil { continue } label := fmt.Sprintf("#%d", *a.ID) if a.InitiatorID != nil { if u, ok := initiators[*a.InitiatorID]; ok && u.FullName != nil { label += " " + *u.FullName } } if a.DepartmentID != nil { if d, ok := departments[*a.DepartmentID]; ok && d.Name != nil { label += " — " + *d.Name } } kb.Row(tgkit.Btn(label, fmt.Sprintf("obs_approval:%d", *a.ID))) } kb.Row(tgkit.BtnStyled(tgkit.ButtonStyleBack, "К темам", "obs_back_topics")) return kb.Build() } func BuildReportDateToMenu() interface{} { return tgkit.NewInlineKeyboard(). Row(tgkit.Btn("📤 Выгрузить (по сегодня)", "report_generate")). Row(tgkit.Btn("Указать даты", "report_set_dates")). Build() } // ── Доработка ─────────────────────────────────────────────────── func BuildRevisionOptions(approvalID uint64) interface{} { return tgkit.NewInlineKeyboard(). Row(tgkit.Btn("✏️ Изменить текст", fmt.Sprintf("revision_edit_text:%d", approvalID))). Row(tgkit.Btn("📎 Добавить файлы", fmt.Sprintf("revision_add_files:%d", approvalID))). Row(tgkit.BtnStyled(tgkit.ButtonStyleSuccess, "Отправить на повторное согласование", fmt.Sprintf("revision_resubmit:%d", approvalID))). Row(tgkit.BtnStyled(tgkit.ButtonStyleDanger, "Отозвать заявку", fmt.Sprintf("appr_revoke:%d", approvalID))). Build() } func BuildRevisionRejectOptions(approvalID uint64) interface{} { return tgkit.NewInlineKeyboard(). Row(tgkit.Btn("💬 Указать причину", fmt.Sprintf("appr_revision_comment:%d", approvalID))). Row(tgkit.Btn("↩️ Вернуть без комментария", fmt.Sprintf("appr_revision_skip:%d", approvalID))). Build() } func BuildRevisionAttachCancel(approvalID uint64) interface{} { return tgkit.NewInlineKeyboard(). Row(tgkit.BtnStyled(tgkit.ButtonStyleDanger, "Отмена", fmt.Sprintf("revision_attach_cancel:%d", approvalID))). Build() } func BuildRevokeTaskConfirmation(taskID uint64, approvalID uint64) tgbotapi.InlineKeyboardMarkup { return tgbotapi.NewInlineKeyboardMarkup( tgbotapi.NewInlineKeyboardRow( tgbotapi.NewInlineKeyboardButtonData( "✅ Нет, изменений не вносил", fmt.Sprintf("revoke_task_no_changes:%d:%d", taskID, approvalID), ), ), tgbotapi.NewInlineKeyboardRow( tgbotapi.NewInlineKeyboardButtonData( "⚠️ Да, изменения были", fmt.Sprintf("revoke_task_has_changes:%d:%d", taskID, approvalID), ), ), ) }