File size: 5,065 Bytes
827ace5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
85
86
87
88
89
90
91
92
93
94
95
class CustomHeader extends HTMLElement {
    connectedCallback() {
        this.attachShadow({ mode: 'open' });
        this.shadowRoot.innerHTML = `
            <style>
                .header {
                    height: 4rem;
                    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
                }
                .dark .header {
                    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
                }
                .avatar {
                    width: 2.5rem;
                    height: 2.5rem;
                }
                .dropdown {
                    transition: all 0.3s ease;
                    transform-origin: top right;
                }
            </style>
            <header class="header fixed top-0 left-0 right-0 z-30 bg-white dark:bg-secondary-500 flex items-center justify-between px-4">
                <div class="flex items-center space-x-4">
                    <button id="sidebarToggle" class="p-2 rounded-full hover:bg-gray-100 dark:hover:bg-secondary-600">
                        <i data-feather="menu"></i>
                    </button>
                    <h1 class="text-xl font-bold text-primary-500">ChatFusion Pro</h1>
                </div>
                
                <div class="flex items-center space-x-4">
                    <button id="themeToggle" class="p-2 rounded-full hover:bg-gray-100 dark:hover:bg-secondary-600">
                        <i data-feather="moon"></i>
                    </button>
                    <button id="messengerToggle" class="p-2 rounded-full hover:bg-gray-100 dark:hover:bg-secondary-600">
                        <i data-feather="message-square"></i>
                    </button>
                    
                    <div class="relative">
                        <button id="profileToggle" class="flex items-center space-x-2 focus:outline-none">
                            <div class="avatar rounded-full bg-primary-500 flex items-center justify-center text-white">
                                <i data-feather="user"></i>
                            </div>
                            <span class="hidden md:inline font-medium text-gray-700 dark:text-gray-300">User</span>
                            <i data-feather="chevron-down" class="w-4 h-4 text-gray-500"></i>
                        </button>
                        
                        <div id="profileDropdown" class="dropdown absolute right-0 mt-2 w-48 bg-white dark:bg-secondary-500 rounded-md shadow-lg py-1 z-40 hidden origin-top-right">
                            <a href="#" class="block px-4 py-2 text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-secondary-600">Profile</a>
                            <a href="#" class="block px-4 py-2 text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-secondary-600">Settings</a>
                            <a href="#" class="block px-4 py-2 text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-secondary-600">Log out</a>
                        </div>
                    </div>
                </div>
            </header>
        `;

        // Add event listeners
        this.shadowRoot.getElementById('themeToggle').addEventListener('click', () => {
            document.dispatchEvent(new CustomEvent('themeToggle'));
            feather.replace();
        });

        this.shadowRoot.getElementById('sidebarToggle').addEventListener('click', () => {
            const currentState = localStorage.getItem('sidebarState') || 'expanded';
            const newState = currentState === 'expanded' ? 'collapsed' : 'expanded';
            localStorage.setItem('sidebarState', newState);
            document.dispatchEvent(new CustomEvent('sidebarStateChange', { detail: newState }));
        });

        this.shadowRoot.getElementById('messengerToggle').addEventListener('click', () => {
            const currentState = localStorage.getItem('messengerState') || 'expanded';
            const newState = currentState === 'expanded' ? 'collapsed' : 'expanded';
            localStorage.setItem('messengerState', newState);
            document.dispatchEvent(new CustomEvent('messengerStateChange', { detail: newState }));
        });

        // Profile dropdown toggle
        const profileToggle = this.shadowRoot.getElementById('profileToggle');
        const profileDropdown = this.shadowRoot.getElementById('profileDropdown');
        profileToggle.addEventListener('click', () => {
            const isHidden = profileDropdown.classList.toggle('hidden');
            profileDropdown.classList.toggle('scale-95', !isHidden);
            profileDropdown.classList.toggle('scale-100', isHidden);
            profileDropdown.classList.toggle('opacity-0', !isHidden);
        });

        // Close dropdown when clicking outside
        document.addEventListener('click', (event) => {
            if (!this.shadowRoot.contains(event.target)) {
                profileDropdown.classList.add('hidden');
            }
        });
    }
}
customElements.define('custom-header', CustomHeader);