import { ExternalLink, Link } from "lucide-react" import { useTranslation } from "react-i18next" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { useApiKeys } from "../../hooks/use-api-keys" import { KeyStatusIndicator } from "./key-status-indicator" interface OAuthField { key: string label: string placeholder: string type?: "text" | "password" optional?: boolean } interface OAuthConnectionProps { service: string credentials: any onUpdate: (credentials: any) => void fields: OAuthField[] links?: Array<{ text: string url: string }> } /** * Компонент для настройки OAuth подключений * Поддерживает множественные поля и авторизацию */ export function OAuthConnection({ service, credentials, onUpdate, fields, links = [] }: OAuthConnectionProps) { const { t } = useTranslation() const { getApiKeyStatus, saveOAuthCredentials } = useApiKeys() const status = getApiKeyStatus(service) const handleFieldChange = (key: string, value: string) => { onUpdate({ ...credentials, [key]: value, }) } const handleClearField = (key: string) => { onUpdate({ ...credentials, [key]: "", }) } const handleInitiateOAuth = async () => { try { // Simple OAuth credentials save for now if (credentials.clientId && credentials.clientSecret) { await saveOAuthCredentials(service, credentials.clientId, credentials.clientSecret) } } catch (error) { console.error(`OAuth error for ${service}:`, error) } } const isReadyForOAuth = fields .filter((field) => !field.optional) .every((field) => (credentials[field.key] || "").length > 0) return (
{t( "dialogs.userSettings.connectionSuccess", "Подключение успешно настроено. Вы можете публиковать контент.", )}
{t("dialogs.userSettings.connectionError", "Ошибка подключения. Проверьте данные и повторите авторизацию.")}