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" ) // BuildDirectorNotificationCategoriesMenu — мультиселект категорий с галочками. // subscribedIDs — те category_id, на которые директор уже подписан. func BuildDirectorNotificationCategoriesMenu(categories []*typescore.ApprovalTopicCategory, subscribedIDs []uint64, page int) tgbotapi.InlineKeyboardMarkup { const perPage = 8 subscribed := make(map[uint64]bool, len(subscribedIDs)) for _, id := range subscribedIDs { subscribed[id] = true } total := len(categories) 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 _, c := range categories[start:end] { if c.ID == nil || c.Name == nil { continue } label := *c.Name if subscribed[*c.ID] { label = "✅ " + label } else { label = "⬜ " + label } // page передаём в callback, чтобы после тоггла вернуться на ту же страницу kb.Row(tgkit.Btn(label, fmt.Sprintf("dir_notif_toggle:%d:%d", *c.ID, page))) } if totalPages > 1 { kb.Rows = append(kb.Rows, buildPageRow(page, totalPages, "dir_notif_page", "dir_notif_page_noop")) } kb.Row(tgkit.BtnStyled(tgkit.ButtonStyleSuccess, "Готово", "dir_notif_done")) return kb.Build() } 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() } // BuildObserverTopicMenuFromDB — строит меню тем наблюдения из БД func BuildObserverTopicMenuFromDB(topics []*typescore.ApprovalTopic, 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] { if t.ID == nil || t.Name == nil || t.Code == nil { continue } 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 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 BuildReportDateToMenu() interface{} { return tgkit.NewInlineKeyboard(). Row(tgkit.Btn("📤 Выгрузить (по сегодня)", "report_generate")). Row(tgkit.Btn("Указать даты", "report_set_dates")). Build() } func BuildRevisionOptions(approvalID uint64, commentsCount int) interface{} { viewLabel := "💬 Посмотреть все комментарии" if commentsCount > 0 { viewLabel = fmt.Sprintf("💬 Посмотреть все комментарии (%d)", commentsCount) } 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.Btn(viewLabel, fmt.Sprintf("appr_view_comments:%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), ), ), ) } func buildCommentsButton(approvalID uint64, commentsCount int) tgkit.InlineButton { label := "💬 Посмотреть все комментарии" if commentsCount > 0 { label = fmt.Sprintf("💬 Посмотреть все комментарии (%d)", commentsCount) } return tgkit.Btn(label, fmt.Sprintf("appr_view_comments:%d", approvalID)) } // BuildTaskTransferUserMenu — список пользователей для передачи задачи func BuildTaskTransferUserMenu(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("task_transfer_user:%d", *u.ID))) } if totalPages > 1 { kb.Rows = append(kb.Rows, buildPageRow(page, totalPages, "task_transfer_page", "task_transfer_noop")) } kb.Row(tgkit.BtnStyled(tgkit.ButtonStyleBack, "Отмена", "task_transfer_cancel")) return kb.Build() } // BuildTaskTransferConfirmation — кнопки Принять/Отклонить для получателя запроса func BuildTaskTransferConfirmation(transferID uint64) tgbotapi.InlineKeyboardMarkup { return tgkit.NewInlineKeyboard(). Row( tgkit.BtnStyled(tgkit.ButtonStyleSuccess, "✅ Принять", fmt.Sprintf("task_transfer_accept:%d", transferID)), tgkit.BtnStyled(tgkit.ButtonStyleDanger, "❌ Отклонить", fmt.Sprintf("task_transfer_decline:%d", transferID)), ). Build() } // BuildRevocationApprovalDecision — Да/Нет для согласующего, дающего согласие на отзыв func BuildRevocationApprovalDecision(approvalID uint64, requestID uint64, commentsCount int) tgbotapi.InlineKeyboardMarkup { return tgkit.NewInlineKeyboard(). Row( tgkit.BtnStyled(tgkit.ButtonStyleSuccess, "✅ Да", fmt.Sprintf("revoke_appr_yes:%d", requestID)), tgkit.BtnStyled(tgkit.ButtonStyleDanger, "❌ Нет", fmt.Sprintf("revoke_appr_no:%d", requestID)), ). Row( tgkit.Btn("💬 Добавить комментарий", fmt.Sprintf("appr_comment:%d", approvalID)), buildCommentsButton(approvalID, commentsCount), ). Build() } func BuildDailyReminderKeyboard(hasRevisions, hasTasks, hasApprovals bool) tgbotapi.InlineKeyboardMarkup { kb := tgkit.NewInlineKeyboard() if hasRevisions { kb.Row(tgkit.Btn("К доработкам", "reminder_revisions")) } if hasTasks { kb.Row(tgkit.Btn("К задачам", "reminder_tasks")) } if hasApprovals { kb.Row(tgkit.Btn("К заявкам", "reminder_approvals")) } return kb.Build() }