import { escapeHtml } from '../util.js';
import { logoLockup } from '../logo.js';
import { renderCornerRail } from '../cornerRail.js';
import { attachTooltips } from '../tooltip.js';
import { renderTopRail } from '../topRail.js';
import { api, ApiError } from '../api.js';
import { getUser } from '../auth.js';
import { CLOSE_ICON } from './icons.js';
// Submitting a passage, and - for moderators - reviewing what others have
// submitted. A bundled dataset stops growing at whatever fits in the
// repository; this is how a corpus gets past that.
const CATEGORIES = [
'quotes', 'literature', 'movies', 'anime', 'science', 'history',
'technology', 'nature', 'philosophy', 'business', 'general',
'programming', 'shell', 'sysadmin', 'hacking',
];
// Mirrors the server's own limits, so the count turns red before a submission
// is rejected rather than after.
const MIN_CONTENT = 40;
const MAX_CONTENT = 600;
export function renderContributeScreen(root, { onBack, onShowStats, onShowPlaceholder, onShowAccount, onShowLeaderboard, onShowFriends, onShowMultiplayer, onShowStore }) {
let mine = [];
let queue = [];
let isModerator = false;
let isAdmin = false;
let roleHolders = [];
let userSearch = [];
let orders = [];
let cleanupInner = null;
function statusLabel(s) {
if (s === 'approved') return 'Approved';
if (s === 'rejected') return 'Not accepted';
return 'Awaiting review';
}
async function load() {
if (!getUser()) return;
try { mine = await api.get('/api/texts/mine'); } catch { mine = []; }
// A 401 here simply means "not a moderator", which is the ordinary
// case rather than an error worth showing.
try { queue = await api.get('/api/texts/queue'); isModerator = true; }
catch { queue = []; isModerator = false; }
// Same shape: a 401 here means "not an administrator", which is the
// ordinary case for almost everyone.
try { roleHolders = await api.get('/api/admin/users'); isAdmin = true; }
catch { roleHolders = []; isAdmin = false; }
// Paid orders waiting to be posted. Only an administrator can see
// them, and they carry a postal address, so this is the one screen in
// the app that shows one.
if (isAdmin) {
try { orders = await api.get('/api/admin/orders'); } catch { orders = []; }
} else {
orders = [];
}
}
function submissionRow(s, moderating) {
return `