HEX
Server: LiteSpeed
System: Linux houston.panomity.com 6.8.0-100-generic #100-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 13 16:40:06 UTC 2026 x86_64
User: nudepix (1011)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //tmp/bewertemich-sharePlaybooks-loop.js
import { buildComparisonShareUrl, buildShareUrl } from '../../utils/tracking.js';

const formatScore = (avgScore, votes) => {
  if (!avgScore || votes < 3) return 'noch kein klares Signal';
  return `${avgScore.toFixed(1)}/10 bei ${votes} Stimmen`;
};

const buildWhatsappHref = (text, url) => `https://wa.me/?text=${encodeURIComponent(`${text} ${url}`)}`;

const buildTelegramHref = (text, url) =>
  `https://t.me/share/url?url=${encodeURIComponent(url)}&text=${encodeURIComponent(text)}`;

const remainingVotesText = (votes) => {
  const remaining = Math.max(0, 5 - Number(votes || 0));
  if (remaining <= 0) return 'Ich hole mir gerade noch ein paar zusätzliche Stimmen dazu.';
  return `Mir fehlen noch ${remaining} ehrliche Stimme${remaining === 1 ? '' : 'n'}.`;
};

export const buildPhotoInvitePlaybook = ({ photoId, avgScore, votes, surface = 'upload_success' }) => {
  const summary = formatScore(avgScore, votes);
  const summarySentence = !avgScore || votes < 3
    ? 'Ich sammele gerade die ersten ehrlichen Stimmen.'
    : `Aktuell steht das Bild bei ${summary}.`;
  const followupText = `Kurzer Reminder: ${remainingVotesText(votes)} Kannst du mein Profilbild bitte noch kurz bewerten?`;

  const directWhatsappUrl = buildShareUrl(photoId, { source: 'whatsapp_direct', surface });
  const groupWhatsappUrl = buildShareUrl(photoId, { source: 'whatsapp_group', surface });
  const directTelegramUrl = buildShareUrl(photoId, { source: 'telegram_direct', surface });
  const groupTelegramUrl = buildShareUrl(photoId, { source: 'telegram_group', surface });
  const followupCopyUrl = buildShareUrl(photoId, { source: 'copy_followup', surface });

  return [
    {
      id: 'whatsapp_direct',
      label: 'WhatsApp direkt',
      goal: '3 Kontakte',
      description: 'Persönliche DMs liefern fast immer die ersten Stimmen am schnellsten.',
      href: buildWhatsappHref(`Kurzer ehrlicher Check? ${summarySentence}`, directWhatsappUrl),
      source: 'whatsapp_direct'
    },
    {
      id: 'telegram_direct',
      label: 'Telegram direkt',
      goal: '2 Kontakte',
      description: 'Gut für die zweite Welle, wenn du schnelle Antworten willst.',
      href: buildTelegramHref(`Kannst du mir kurz ehrliches Feedback geben? ${summarySentence}`, directTelegramUrl),
      source: 'telegram_direct'
    },
    {
      id: 'whatsapp_group',
      label: 'WhatsApp Gruppe',
      goal: '1 Gruppe',
      description: 'Sobald die ersten 2 bis 3 Stimmen da sind, lohnt sich die kleine Gruppe.',
      href: buildWhatsappHref('Brauche einen kurzen Profilbild-Check von ein paar Leuten:', groupWhatsappUrl),
      source: 'whatsapp_group'
    },
    {
      id: 'telegram_group',
      label: 'Telegram Gruppe',
      goal: '1 Gruppe',
      description: 'Funktioniert gut für ein breiteres, aber immer noch kontrolliertes Feedback.',
      href: buildTelegramHref('Kurzer Profilbild-Check. Welche Wirkung hat das Foto auf dich?', groupTelegramUrl),
      source: 'telegram_group'
    },
    {
      id: 'copy_followup',
      label: 'Reminder kopieren',
      goal: 'Follow-up',
      description: 'Wenn nach ein paar Stunden noch Stimmen fehlen, sende diese Erinnerung.',
      copyText: `${followupText} ${followupCopyUrl}`,
      source: 'copy_followup'
    }
  ];
};

export const buildComparisonInvitePlaybook = ({
  comparisonId,
  title,
  leftPercent,
  rightPercent,
  totalVotes,
  surface = 'compare_page'
}) => {
  const compareUrlDirect = buildComparisonShareUrl(comparisonId, { source: 'whatsapp_direct', surface });
  const compareUrlTelegram = buildComparisonShareUrl(comparisonId, { source: 'telegram_direct', surface });
  const compareUrlGroup = buildComparisonShareUrl(comparisonId, { source: 'whatsapp_group', surface });
  const compareUrlFollowup = buildComparisonShareUrl(comparisonId, { source: 'copy_followup', surface });
  const comparisonSummary = totalVotes > 0
    ? `Aktuell ${leftPercent}% zu ${rightPercent}% bei ${totalVotes} Stimmen.`
    : 'Es gibt noch kein Ergebnis, deshalb ist jede Stimme gerade wertvoll.';

  return [
    {
      id: 'whatsapp_direct',
      label: 'WhatsApp direkt',
      goal: '3 Kontakte',
      description: 'Am stärksten für schnelle A/B-Entscheidungen.',
      href: buildWhatsappHref(`${title || 'Welches Profilbild wirkt besser?'} ${comparisonSummary}`, compareUrlDirect),
      source: 'whatsapp_direct'
    },
    {
      id: 'telegram_direct',
      label: 'Telegram direkt',
      goal: '2 Kontakte',
      description: 'Die zweite schnelle Welle für weitere Direktstimmen.',
      href: buildTelegramHref(`${title || 'Welches Profilbild wirkt besser?'} ${comparisonSummary}`, compareUrlTelegram),
      source: 'telegram_direct'
    },
    {
      id: 'whatsapp_group',
      label: 'WhatsApp Gruppe',
      goal: '1 Gruppe',
      description: 'Sobald 4 bis 5 Stimmen da sind, kannst du in eine kleine Gruppe gehen.',
      href: buildWhatsappHref('Kurze Entscheidungshilfe: Bild A oder Bild B?', compareUrlGroup),
      source: 'whatsapp_group'
    },
    {
      id: 'copy_followup',
      label: 'Reminder kopieren',
      goal: 'Follow-up',
      description: 'Hilft, wenn der Vergleich nach dem ersten Schub stehen bleibt.',
      copyText: `Kurzer Reminder: Ich brauche noch ein paar Stimmen für meinen Bildvergleich. ${compareUrlFollowup}`,
      source: 'copy_followup'
    }
  ];
};