File size: 3,106 Bytes
908623a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
document.addEventListener('DOMContentLoaded', function() {
    // Initialize tooltips
    const tooltipTriggers = document.querySelectorAll('[data-tooltip]');
    tooltipTriggers.forEach(trigger => {
        trigger.addEventListener('mouseenter', function() {
            const tooltip = document.createElement('div');
            tooltip.className = 'absolute z-10 px-3 py-2 text-sm text-white bg-gray-900 rounded-lg shadow-lg';
            tooltip.textContent = this.getAttribute('data-tooltip');
            
            const rect = this.getBoundingClientRect();
            tooltip.style.top = `${rect.top - 40}px`;
            tooltip.style.left = `${rect.left + rect.width / 2 - tooltip.offsetWidth / 2}px`;
            
            document.body.appendChild(tooltip);
            this._tooltip = tooltip;
        });
        
        trigger.addEventListener('mouseleave', function() {
            if (this._tooltip) {
                document.body.removeChild(this._tooltip);
                this._tooltip = null;
            }
        });
    });

    // Toggle policy card details
    document.addEventListener('click', function(e) {
        if (e.target.closest('.toggle-details')) {
            const card = e.target.closest('custom-policy-card');
            const details = card.shadowRoot.querySelector('.policy-details');
            const icon = card.shadowRoot.querySelector('.toggle-icon');
            
            details.classList.toggle('hidden');
            icon.setAttribute('data-feather', details.classList.contains('hidden') ? 'chevron-down' : 'chevron-up');
            feather.replace();
        }
    });

    // Chat functionality
    const chatInput = document.querySelector('aside input[type="text"]');
    const chatSendBtn = document.querySelector('aside button');
    const chatContainer = document.getElementById('chat-container');

    function addMessage(type, message) {
        const bubble = document.createElement('custom-chat-bubble');
        bubble.setAttribute('type', type);
        bubble.setAttribute('message', message);
        chatContainer.appendChild(bubble);
        chatContainer.scrollTop = chatContainer.scrollHeight;
    }

    function handleSendMessage() {
        const message = chatInput.value.trim();
        if (message) {
            addMessage('user', message);
            chatInput.value = '';
            
            // Simulate AI response
            setTimeout(() => {
                const responses = [
                    "I found this information in the 2025 Agricultural Support Policy: ...",
                    "According to the latest guidelines from the Ministry of Agriculture...",
                    "The policy you're asking about was updated last month. Here are the key points..."
                ];
                addMessage('ai', responses[Math.floor(Math.random() * responses.length)]);
            }, 1000);
        }
    }

    chatSendBtn.addEventListener('click', handleSendMessage);
    chatInput.addEventListener('keypress', function(e) {
        if (e.key === 'Enter') handleSendMessage();
    });
});