import { html, render } from "/js/lib/lit-html.js";
import { Component } from "/js/components/component.js";
import { scrollLocks } from "/js/scrollLocks.js";
import { displayRelativeTime, enableDragToDismiss } from "/js/utils.js";
import { Signal, ReactiveStore, effect, untrack } from "/js/signals.js";
import { confirmModal } from "/js/modals/confirm.modal.js";
import { showToast } from "/js/toasts.js";
import { trashCanIconTemplate } from "/js/templates/icons/trashCanIcon.template.js";
import { playIconTemplate } from "/js/templates/icons/playIcon.template.js";
import {
getLocalRefsFromDraft,
getImagesFromDraftPost,
} from "/js/dataHelpers.js";
import { getDraftDeviceId } from "/js/drafts.js";
import "/js/components/infinite-scroll-container.js";
// GIFs are serialized by bsky as external URLs with ww/hh query params on
// known GIF proxy hostnames - no local bytes involved.
const GIF_HOSTNAMES = ["media.tenor.com", "static.klipy.com"];
function parseGifFromUrl(url) {
let parsed = null;
try {
parsed = new URL(url);
} catch (error) {
return null;
}
if (!GIF_HOSTNAMES.includes(parsed.hostname)) {
return null;
}
const width = Number(parsed.searchParams.get("ww"));
const height = Number(parsed.searchParams.get("hh"));
if (!width || !height) {
return null;
}
return {
url,
width,
height,
alt: parsed.searchParams.get("alt") ?? "",
};
}
function draftTagTemplate(name, label, { warning = false } = {}) {
return html`${label}`;
}
function draftMediaTemplate({ images, gif, video }) {
const thumbs = [];
for (const image of images) {
if (image.previewUrl) {
thumbs.push(
html``,
);
}
}
if (gif) {
thumbs.push(
html`
`,
);
}
if (video?.exists) {
thumbs.push(
html`