Spaces:
Running
Running
| class AccountRow extends HTMLElement { | |
| constructor() { | |
| super(); | |
| this.attachShadow({ mode: 'open' }); | |
| this._account = null; | |
| } | |
| static get observedAttributes() { | |
| return ['account-id', 'username', 'user-id', 'platform', 'status', 'created-at', 'avatar']; | |
| } | |
| connectedCallback() { | |
| this.render(); | |
| } | |
| attributeChangedCallback() { | |
| this.render(); | |
| } | |
| render() { | |
| const accountId = this.getAttribute('account-id'); | |
| const username = this.getAttribute('username') || '@unknown'; | |
| const userId = this.getAttribute('user-id') || 'unknown'; | |
| const platform = this.getAttribute('platform') || 'twitter'; | |
| const status = this.getAttribute('status') || 'INACTIVE'; | |
| const createdAt = this.getAttribute('created-at') || new Date().toISOString(); | |
| const avatar = this.getAttribute('avatar') || `https://static.photos/people/200x200/${accountId || '1'}`; | |
| const isActive = status === 'ACTIVE'; | |
| const platformIcon = platform === 'twitter' | |
| ? '<svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4 text-[#1da1f2]" viewBox="0 0 24 24" fill="currentColor"><path d="M23.953 4.57a10 10 0 01-2.825.775 4.958 4.958 0 002.163-2.723c-.951.555-2.005.959-3.127 1.184a4.92 4.92 0 00-8.384 4.482C7.69 8.095 4.067 6.13 1.64 3.162a4.822 4.822 0 00-.666 2.475c0 1.71.87 3.213 2.188 4.096a4.904 4.904 0 01-2.228-.616v.06a4.923 4.923 0 003.946 4.827 4.996 4.996 0 01-2.212.085 4.936 4.936 0 004.604 3.417 9.867 9.867 0 01-6.102 2.105c-.39 0-.779-.023-1.17-.067a13.995 13.995 0 007.557 2.209c9.053 0 13.998-7.496 13.998-13.985 0-.21 0-.42-.015-.63A9.935 9.935 0 0024 4.59z"/></svg>' | |
| : '<svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4 text-[#25d366]" viewBox="0 0 24 24" fill="currentColor"><path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.35-8.413z"/></svg>'; | |
| this.shadowRoot.innerHTML = ` | |
| <style> | |
| @import url('https://cdn.tailwindcss.com'); | |
| :host { | |
| display: table-row; | |
| } | |
| .row-hover { | |
| transition: all 0.2s ease; | |
| } | |
| .row-hover:hover { | |
| background-color: rgba(249, 250, 251, 0.8); | |
| } | |
| .status-active { | |
| animation: pulse-subtle 2s ease-in-out infinite; | |
| } | |
| @keyframes pulse-subtle { | |
| 0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); } | |
| 50% { box-shadow: 0 0 0 4px rgba(34, 197, 94, 0); } | |
| } | |
| </style> | |
| <tr class="row-hover group"> | |
| <td class="px-6 py-4 whitespace-nowrap"> | |
| <div class="flex items-center"> | |
| <div class="flex-shrink-0 h-10 w-10"> | |
| <img class="h-10 w-10 rounded-full object-cover ring-2 ring-gray-100" src="${avatar}" alt=""> | |
| </div> | |
| <div class="ml-4"> | |
| <div class="text-sm font-medium text-amber-600 hover:text-amber-700 cursor-pointer">${username}</div> | |
| <div class="text-xs text-gray-500">ID: ${userId}</div> | |
| </div> | |
| </div> | |
| </td> | |
| <td class="px-6 py-4 whitespace-nowrap"> | |
| <div class="flex items-center gap-2"> | |
| ${platformIcon} | |
| <span class="text-sm text-gray-700 capitalize">${platformName}</span> | |
| </div> | |
| </td> | |
| <td class="px-6 py-4 whitespace-nowrap"> | |
| <div class="text-sm text-gray-700">${this.formatDate(createdAt)}</div> | |
| <div class="text-xs text-gray-500">${this.timeAgo(createdAt)}</div> | |
| </td> | |
| <td class="px-6 py-4 whitespace-nowrap"> | |
| ${isActive ? | |
| `<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-800 status-active"><span class="w-1.5 h-1.5 bg-green-500 rounded-full mr-1.5 animate-pulse"></span>Active</span>` : | |
| `<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-yellow-100 text-yellow-800"><span class="w-1.5 h-1.5 bg-yellow-500 rounded-full mr-1.5"></span>Inactive</span>` | |
| } | |
| </td> | |
| <td class="px-6 py-4 whitespace-nowrap text-right"> | |
| ${isActive ? | |
| `<button class="inline-flex items-center gap-1.5 px-3 py-1.5 border border-transparent text-xs font-medium rounded-md text-white bg-red-600 hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500 transition-all duration-200 active:scale-95"><svg xmlns="http://www.w3.org/2000/svg" class="w-3 h-3" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18.36 6.64a9 9 0 1 1-12.73 0"></path><line x1="12" y1="2" x2="12" y2="12"></line></svg>Deactivate</button>` : | |
| `<button class="inline-flex items-center gap-1.5 px-3 py-1.5 border border-transparent text-xs font-medium rounded-md text-white bg-green-600 hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500 transition-all duration-200 active:scale-95"><svg xmlns="http://www.w3.org/2000/svg" class="w-3 h-3" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="5 3 19 12 5 21 5 3"></polygon></svg>Activate</button>` | |
| } | |
| </td> | |
| </tr> | |
| `; | |
| // Add event listener to the button | |
| const button = this.shadowRoot.querySelector('button'); | |
| if (button) { | |
| button.addEventListener('click', () => { | |
| this.dispatchEvent(new CustomEvent('toggle-status', { | |
| detail: { accountId: this.getAttribute('account-id') }, | |
| bubbles: true, | |
| composed: true | |
| })); | |
| }); | |
| } | |
| } | |
| formatDate(dateString) { | |
| const date = new Date(dateString); | |
| return date.toLocaleDateString('en-US', { | |
| year: 'numeric', | |
| month: 'short', | |
| day: 'numeric' | |
| }); | |
| } | |
| timeAgo(dateString) { | |
| const date = new Date(dateString); | |
| const now = new Date(); | |
| const seconds = Math.floor((now - date) / 1000); | |
| let interval = Math.floor(seconds / 31536000); | |
| if (interval > 1) return `${interval} years ago`; | |
| if (interval === 1) return '1 year ago'; | |
| interval = Math.floor(seconds / 2592000); | |
| if (interval > 1) return `${interval} months ago`; | |
| if (interval === 1) return '1 month ago'; | |
| interval = Math.floor(seconds / 86400); | |
| if (interval > 1) return `${interval} days ago`; | |
| if (interval === 1) return '1 day ago'; | |
| interval = Math.floor(seconds / 3600); | |
| if (interval > 1) return `${interval} hours ago`; | |
| if (interval === 1) return '1 hour ago'; | |
| interval = Math.floor(seconds / 60); | |
| if (interval > 1) return `${interval} minutes ago`; | |
| return 'Just now'; | |
| } | |
| } | |
| customElements.define('account-row', AccountRow); |