File size: 2,746 Bytes
5669112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
() => {
    // Landing page toggle logic
    const landingPage = document.getElementById('landing-page-container');
    const chatbot = document.getElementById('chatbot');
    const msgInput = document.querySelector('#input-row textarea, #input-row input[type="text"]');

    if (!landingPage || !chatbot) return;

    function toggleLanding() {
        // Check if chatbot has any messages
        const messages = chatbot.querySelectorAll('[data-testid="bot"], [data-testid="user"], [class*="message"]');
        const hasMessages = messages.length > 0;

        // Also check for empty state indicators
        const emptyState = chatbot.querySelector('.empty-state, .placeholder, [class*="empty"]');
        const chatColumn = document.getElementById('chat-column');

        if (hasMessages && !emptyState) {
            landingPage.classList.add('hidden');
            if (chatColumn) chatColumn.classList.remove('landing-active');
        } else {
            landingPage.classList.remove('hidden');
            if (chatColumn) chatColumn.classList.add('landing-active');
        }
    }

    // Initial check
    toggleLanding();

    // Set up mutation observer to watch for chat changes
    const observer = new MutationObserver((mutations) => {
        let shouldToggle = false;
        for (const mutation of mutations) {
            if (mutation.type === 'childList' || mutation.type === 'subtree') {
                shouldToggle = true;
                break;
            }
        }
        if (shouldToggle) {
            // Debounce the toggle check
            clearTimeout(window._landingToggleTimeout);
            window._landingToggleTimeout = setTimeout(toggleLanding, 100);
        }
    });

    observer.observe(chatbot, {
        childList: true,
        subtree: true,
        attributes: true,
        attributeFilter: ['class']
    });

    // Also watch for the input area to handle new chat creation
    const inputRow = document.getElementById('input-row');
    if (inputRow) {
        observer.observe(inputRow, {
            childList: true,
            subtree: true
        });
    }

    // Click on landing prompt to focus input
    const landingPrompt = document.querySelector('.landing-prompt');
    if (landingPrompt && msgInput) {
        landingPrompt.addEventListener('click', () => {
            msgInput.focus();
            msgInput.click();
        });
    }

    // Store reference for cleanup
    window._landingPageObserver = observer;
    window._landingPage = landingPage;
    
    function setVH() {
        document.documentElement.style.setProperty(
            '--vh',
            `${window.innerHeight}px`
        );
    }

    setVH();
    // window.addEventListener('resize', setVH);
}