---
// Home page sections (site permission): rename, add, remove and reorder sections; choose and order the poets of a
// chosen-poets section (e.g. مقبول شعرا); sort a section by hand, alphabetically or by timeline. Saved all at once.
import Base from '../../layouts/Base.astro';
import ModNav from '../../components/ModNav.astro';
import { asUser, COOKIE } from '../../lib/auth';
import { centuryName } from '../../lib/urdu';
const me = Astro.locals.user;
if (!me) return Astro.redirect(`/signin?next=${Astro.url.pathname}`);
const token = Astro.cookies.get(COOKIE)!.value;
let error = '', done = '';
if (Astro.request.method === 'POST') {
let sections: unknown = null;
try { sections = JSON.parse(String((await Astro.request.formData()).get('layout'))); } catch {}
const r = await asUser(token, '/api/mod/site', { sections });
if (r.ok) done = 'سرورق محفوظ ہو گیا';
else error = r.data.error ?? 'کچھ غلط ہو گیا';
}
const res = await asUser(token, '/api/mod/site');
const centuries = Object.fromEntries(Array.from({ length: 16 }, (_, c) => [c, centuryName(c || null)]));
---
{res.data.error ?? 'یہ صفحہ دیکھنے کی اجازت نہیں'}
: ( <> {error &&{error}
} {done &&{done} · سرورق دیکھیں
}حصوں کے نام بدلیں، ↑ ↓ سے ان کی جگہ بدلیں، اور ہر حصے کی ترتیب چنیں: دستی، حروفِ تہجی یا زمانی (پیدائش کے سال سے)۔ صدی کے حصے میں اس صدی میں پیدا ہونے والے تمام شعرا خود آتے ہیں؛ «منتخب شعرا» کے حصے میں آپ شعرا چن کر ترتیب دیتے ہیں۔
> )}