"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UpdateStreamTitleDialog = UpdateStreamTitleDialog;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const ui_1 = require("../ui");
function UpdateStreamTitleDialog({ livestream, streamerDID, updateLivestream, isLoading, onClose, }) {
    const [title, setTitle] = (0, react_1.useState)(livestream?.record?.title || "");
    const [error, setError] = (0, react_1.useState)(null);
    const toast = (0, ui_1.useToast)();
    (0, react_1.useEffect)(() => {
        if (livestream?.record?.title) {
            setTitle(livestream.record.title);
        }
    }, [livestream?.record?.title]);
    const handleUpdate = async () => {
        setError(null);
        if (!title.trim()) {
            setError("Please enter a stream title");
            return;
        }
        if (!livestream?.uri) {
            setError("No livestream found");
            return;
        }
        try {
            await updateLivestream(livestream.uri, title.trim(), streamerDID);
            toast.show("Stream title updated", "The stream title has been successfully updated.", { duration: 3 });
            onClose();
        }
        catch (err) {
            setError(err instanceof Error ? err.message : "Failed to update stream title");
        }
    };
    return ((0, jsx_runtime_1.jsxs)(ui_1.ResponsiveDialog, { open: true, onOpenChange: (open) => {
            if (!open) {
                onClose();
                setError(null);
                setTitle(livestream?.record?.title || "");
            }
        }, title: "Update Stream Title", description: "Update the title of the livestream.", size: "md", dismissible: false, children: [(0, jsx_runtime_1.jsxs)(ui_1.View, { style: [{ padding: 16, paddingBottom: 0 }], children: [(0, jsx_runtime_1.jsxs)(ui_1.View, { style: [{ marginBottom: 16 }], children: [(0, jsx_runtime_1.jsx)(ui_1.Text, { style: [
                                    { color: ui_1.atoms.colors.gray[300], fontSize: 13, marginBottom: 8 },
                                ], children: "Stream Title" }), (0, jsx_runtime_1.jsx)(ui_1.Textarea, { value: title, onChangeText: (text) => {
                                    setTitle(text);
                                    setError(null);
                                }, placeholder: "Enter stream title...", maxLength: 140, multiline: true, style: [
                                    {
                                        padding: 12,
                                        borderRadius: 8,
                                        backgroundColor: ui_1.atoms.colors.neutral[800],
                                        color: ui_1.atoms.colors.white,
                                        borderWidth: 1,
                                        borderColor: ui_1.atoms.colors.neutral[600],
                                        minHeight: 100,
                                        fontSize: 16,
                                    },
                                ] }), (0, jsx_runtime_1.jsxs)(ui_1.Text, { style: [
                                    { color: ui_1.atoms.colors.gray[400], fontSize: 12, marginTop: 4 },
                                ], children: [title.length, "/140 characters"] })] }), error && ((0, jsx_runtime_1.jsx)(ui_1.View, { style: [
                            {
                                backgroundColor: ui_1.atoms.colors.red[900],
                                padding: 12,
                                borderRadius: 8,
                                borderWidth: 1,
                                borderColor: ui_1.atoms.colors.red[700],
                                marginBottom: 16,
                            },
                        ], children: (0, jsx_runtime_1.jsx)(ui_1.Text, { style: [{ color: ui_1.atoms.colors.red[400], fontSize: 13 }], children: error }) }))] }), (0, jsx_runtime_1.jsxs)(ui_1.DialogFooter, { children: [(0, jsx_runtime_1.jsx)(ui_1.Button, { width: "min", variant: "secondary", onPress: () => {
                            onClose();
                            setError(null);
                            setTitle(livestream?.record?.title || "");
                        }, disabled: isLoading, children: (0, jsx_runtime_1.jsx)(ui_1.Text, { children: "Cancel" }) }), (0, jsx_runtime_1.jsx)(ui_1.Button, { variant: "primary", width: "min", onPress: handleUpdate, disabled: isLoading || !title.trim(), children: (0, jsx_runtime_1.jsx)(ui_1.Text, { children: isLoading ? "Updating..." : "Update Title" }) })] })] }));
}
//# sourceMappingURL=update-stream-title-dialog.js.map