"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PinnedCommentNotification = PinnedCommentNotification;
const jsx_runtime_1 = require("react/jsx-runtime");
const lucide_react_native_1 = require("lucide-react-native");
const react_1 = require("react");
const react_native_1 = require("react-native");
const __1 = require("../../");
const facet_1 = require("../../lib/facet");
const format_handle_1 = require("../../utils/format-handle");
const getRgbColor = (color) => color ? `rgb(${color.red}, ${color.green}, ${color.blue})` : undefined;
function renderSegment(segment, index) {
    if (segment.features && segment.features.length > 0) {
        const ftr = segment.features[0];
        if (ftr.$type === "app.bsky.richtext.facet#link") {
            return ((0, jsx_runtime_1.jsx)(__1.Text, { style: [{ color: "#007AFF" }], onPress: () => react_native_1.Linking.openURL(ftr.uri || ""), children: segment.text }, index));
        }
        if (ftr.$type === "app.bsky.richtext.facet#mention") {
            return ((0, jsx_runtime_1.jsx)(__1.Text, { style: [{ color: "#007AFF" }], children: segment.text }, index));
        }
    }
    return (0, jsx_runtime_1.jsx)(__1.Text, { children: segment.text }, index);
}
function PinnedCommentNotification({ pinnedComment, onDismiss, onUnpin, }) {
    const z = (0, __1.useTheme)();
    const message = pinnedComment.message;
    const pinnedByColor = pinnedComment.pinnedBy?.color || "#bebebe";
    const record = pinnedComment.record;
    const currentStreamer = (0, __1.useLivestreamStore)((state) => state.profile?.did);
    console.log("checking if we can mod", currentStreamer);
    const canActuallyPin = (0, __1.useCanModerate)(currentStreamer)?.canPin;
    const messageRecord = message?.record;
    const [expiresAt] = (0, react_1.useState)(record.expiresAt ? new Date(record.expiresAt) : null);
    (0, react_1.useEffect)(() => {
        if (!expiresAt)
            return;
        const remaining = expiresAt.getTime() - Date.now();
        if (remaining <= 0) {
            onDismiss();
            return;
        }
        const timeout = setTimeout(onDismiss, remaining);
        return () => clearTimeout(timeout);
    }, [expiresAt, onDismiss]);
    const authorName = message ? (0, format_handle_1.formatHandleWithAt)(message.author) : "unknown";
    const authorColor = getRgbColor(message?.chatProfile?.color);
    const segments = messageRecord
        ? (0, facet_1.segmentize)(messageRecord.text, messageRecord.facets)
        : [];
    return ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: [__1.zero.bg.neutral[900], __1.zero.r.lg, { overflow: "hidden" }], children: (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [
                __1.zero.layout.flex.row,
                __1.zero.layout.flex.alignCenter,
                __1.zero.px[3],
                __1.zero.py[2],
                { gap: 8 },
            ], children: [(0, jsx_runtime_1.jsx)(react_native_1.View, { style: { transform: [{ rotate: "-25deg" }] }, children: (0, jsx_runtime_1.jsx)(lucide_react_native_1.Pin, { size: 24, color: authorColor || z.theme.colors.primary, fill: authorColor || z.theme.colors.primary }) }), (0, jsx_runtime_1.jsx)(react_native_1.View, { style: [__1.zero.layout.flex.column, __1.zero.flex.values[1], { gap: 4 }], children: (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [__1.zero.layout.flex.row, { gap: 4, flexWrap: "wrap" }], children: [(0, jsx_runtime_1.jsx)(__1.Text, { style: [
                                    {
                                        fontWeight: "600",
                                        color: authorColor || __1.zero.colors.gray[200],
                                    },
                                ], children: authorName }), segments.map((seg, i) => renderSegment(seg, i))] }) }), (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [__1.zero.layout.flex.row, { gap: 4 }], children: [canActuallyPin && ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { onPress: onUnpin, style: { padding: 4 }, children: (0, jsx_runtime_1.jsx)(lucide_react_native_1.X, { size: 16, color: __1.zero.colors.gray[400] }) })), (0, jsx_runtime_1.jsx)(react_native_1.Pressable, { onPress: onDismiss, style: { padding: 4 }, children: (0, jsx_runtime_1.jsx)(lucide_react_native_1.EyeOff, { size: 16, color: __1.zero.colors.gray[400] }) })] })] }) }));
}
//# sourceMappingURL=pin-notification.js.map