Spaces:
Running
Running
File size: 36,480 Bytes
c1efc64 077dc78 c1efc64 077dc78 c1efc64 077dc78 c1efc64 077dc78 c1efc64 077dc78 c1efc64 077dc78 c1efc64 077dc78 c1efc64 077dc78 c1efc64 077dc78 c1efc64 077dc78 c1efc64 077dc78 c1efc64 077dc78 c1efc64 077dc78 c1efc64 077dc78 c1efc64 077dc78 c1efc64 077dc78 c1efc64 077dc78 c1efc64 077dc78 |
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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 |
<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
<title>پیام رسان مینیمال | MinimalChat</title>
<style>
body {
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
background: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #1e1b4b 100%);
background-attachment: fixed;
-webkit-tap-highlight-color: transparent;
margin: 0;
padding: 0;
color: white;
}
.glass-panel {
background: rgba(255, 255, 255, 0.08);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
border: 1px solid rgba(255, 255, 255, 0.1);
}
.input-minimal {
background: transparent;
border-bottom: 1px solid rgba(255, 255, 255, 0.2);
transition: all 0.3s;
}
.input-minimal:focus {
border-color: rgba(255, 255, 255, 0.6);
outline: none;
}
.message-bubble-me {
background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
border-radius: 16px 16px 4px 16px;
}
.message-bubble-other {
background: rgba(255, 255, 255, 0.12);
border-radius: 16px 16px 16px 4px;
}
.fade-in {
animation: fadeIn 0.3s ease-out;
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.slide-in {
animation: slideIn 0.3s ease-out;
}
@keyframes slideIn {
from {
transform: translateX(100%);
}
to {
transform: translateX(0);
}
}
.slide-out {
animation: slideOut 0.3s ease-out;
}
@keyframes slideOut {
from {
transform: translateX(0);
}
to {
transform: translateX(100%);
}
}
/* Custom Scrollbar */
::-webkit-scrollbar {
width: 4px;
height: 4px;
}
::-webkit-scrollbar-track {
background: transparent;
}
::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, 0.2);
border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
background: rgba(255, 255, 255, 0.3);
}
/* Mobile Optimizations */
@media (max-width: 768px) {
.mobile-sidebar {
position: fixed;
top: 0;
right: 0;
height: 100vh;
height: 100dvh;
width: 85%;
max-width: 300px;
z-index: 40;
transform: translateX(100%);
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.mobile-sidebar.open {
transform: translateX(0);
}
.sidebar-overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.5);
backdrop-filter: blur(4px);
z-index: 35;
opacity: 0;
pointer-events: none;
transition: opacity 0.3s;
}
.sidebar-overlay.active {
opacity: 1;
pointer-events: auto;
}
.chat-container {
position: fixed;
inset: 0;
z-index: 30;
}
.safe-bottom {
padding-bottom: env(safe-area-inset-bottom, 20px);
}
}
/* Touch friendly buttons */
.touch-target {
min-height: 44px;
min-width: 44px;
}
/* Prevent zoom on input focus for iOS */
@media screen and (max-width: 768px) {
input,
textarea,
select {
font-size: 16px;
}
}
/* Message animations */
.message-enter {
animation: messagePop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes messagePop {
0% {
opacity: 0;
transform: scale(0.8) translateY(20px);
}
100% {
opacity: 1;
transform: scale(1) translateY(0);
}
}
/* Loading shimmer */
.shimmer {
background: linear-gradient(90deg, rgba(255, 255, 255, 0.05) 25%, rgba(255, 255, 255, 0.1) 50%, rgba(255, 255, 255, 0.05) 75%);
background-size: 200% 100%;
animation: shimmer 1.5s infinite;
}
@keyframes shimmer {
0% {
background-position: 200% 0;
}
100% {
background-position: -200% 0;
}
}
/* Sticker picker styles */
.sticker-picker {
position: absolute;
bottom: 70px;
right: 0;
width: 100%;
max-height: 300px;
background: rgba(30, 27, 75, 0.95);
border-radius: 12px 12px 0 0;
border: 1px solid rgba(255, 255, 255, 0.1);
overflow-y: auto;
padding: 10px;
display: none;
z-index: 100;
}
.sticker-picker.active {
display: block;
}
.sticker-category {
margin-bottom: 10px;
}
.sticker-category-title {
font-size: 12px;
color: rgba(255, 255, 255, 0.6);
margin-bottom: 5px;
padding-right: 5px;
}
.sticker-grid {
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: 5px;
}
.sticker-item {
width: 100%;
aspect-ratio: 1;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
border-radius: 8px;
transition: background 0.2s;
}
.sticker-item:hover {
background: rgba(255, 255, 255, 0.1);
}
.sticker-item img {
max-width: 80%;
max-height: 80%;
}
/* Profile edit modal */
.profile-edit-modal {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.7);
display: flex;
align-items: center;
justify-content: center;
z-index: 100;
opacity: 0;
pointer-events: none;
transition: opacity 0.3s;
}
.profile-edit-modal.active {
opacity: 1;
pointer-events: auto;
}
.profile-edit-content {
background: #1e1b4b;
border-radius: 16px;
padding: 20px;
width: 90%;
max-width: 400px;
border: 1px solid rgba(255, 255, 255, 0.1);
}
.avatar-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 10px;
margin-top: 15px;
}
.avatar-option {
width: 100%;
aspect-ratio: 1;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
cursor: pointer;
transition: transform 0.2s;
}
.avatar-option:hover {
transform: scale(1.1);
}
.avatar-option.selected {
border: 3px solid #3b82f6;
}
/* Room settings modal */
.room-settings-modal {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.7);
display: flex;
align-items: center;
justify-content: center;
z-index: 100;
opacity: 0;
pointer-events: none;
transition: opacity 0.3s;
}
.room-settings-modal.active {
opacity: 1;
pointer-events: auto;
}
.room-settings-content {
background: #1e1b4b;
border-radius: 16px;
padding: 20px;
width: 90%;
max-width: 400px;
border: 1px solid rgba(255, 255, 255, 0.1);
}
.danger-zone {
border-top: 1px solid rgba(255, 0, 0, 0.3);
padding-top: 15px;
margin-top: 15px;
}
.danger-button {
background: rgba(255, 0, 0, 0.2);
color: #ff6b6b;
border: 1px solid rgba(255, 0, 0, 0.3);
}
.danger-button:hover {
background: rgba(255, 0, 0, 0.3);
}
</style>
</head>
<body class="text-white h-screen h-[100dvh] overflow-hidden selection:bg-blue-500/30 bg-slate-900">
<!-- Toast Container -->
<div id="toast-container" class="fixed top-4 left-1/2 transform -translate-x-1/2 z-50 flex flex-col gap-2 w-full max-w-sm px-4 pointer-events-none">
</div>
<!-- Auth View -->
<div id="auth-view" class="h-full w-full flex items-center justify-center p-4 overflow-y-auto">
<div class="glass-panel p-6 md:p-8 rounded-2xl w-full max-w-md fade-in my-auto">
<div class="text-center mb-6 md:mb-8">
<div class="w-14 h-14 md:w-16 md:h-16 bg-white/10 rounded-full mx-auto flex items-center justify-center mb-4">
<span style="font-size: 24px;">💬</span>
</div>
<h1 class="text-xl md:text-2xl font-bold">پیام رسان مینیمال</h1>
<p class="text-white/50 text-xs md:text-sm mt-1">پیام رسان مینیمال با PHP</p>
</div>
<!-- Tabs -->
<div class="flex gap-4 mb-6 border-b border-white/10 pb-1">
<button onclick="switchAuthTab('login')" id="tab-login" class="flex-1 pb-2 text-sm font-medium border-b-2 border-white text-white transition-colors touch-target flex items-center justify-center">ورود</button>
<button onclick="switchAuthTab('register')" id="tab-register" class="flex-1 pb-2 text-sm font-medium border-b-2 border-transparent text-white/50 hover:text-white transition-colors touch-target flex items-center justify-center">ثبت نام</button>
</div>
<!-- Login Form -->
<form id="login-form" class="space-y-4 md:space-y-5" onsubmit="handleLogin(event)">
<div>
<label class="block text-xs text-white/60 mb-2">شماره موبایل</label>
<input type="tel" id="login-phone" placeholder="09XXXXXXXXX" inputmode="tel" class="w-full input-minimal py-3 text-white placeholder-white/30 touch-target" required>
</div>
<div>
<label class="block text-xs text-white/60 mb-2">رمز عبور</label>
<input type="password" id="login-password" placeholder="••••••••" class="w-full input-minimal py-3 text-white placeholder-white/30 touch-target" required>
</div>
<button type="submit" class="w-full bg-white text-slate-900 font-bold py-3 rounded-lg hover:bg-white/90 transition-colors mt-4 touch-target active:scale-95 transform transition-transform">
ورود
</button>
</form>
<!-- Register Form -->
<form id="register-form" class="space-y-4 md:space-y-5 hidden" onsubmit="handleRegister(event)">
<div>
<label class="block text-xs text-white/60 mb-2">نام کامل</label>
<input type="text" id="reg-name" placeholder="نام شما" class="w-full input-minimal py-3 text-white placeholder-white/30 touch-target" required>
</div>
<div>
<label class="block text-xs text-white/60 mb-2">شماره موبایل</label>
<input type="tel" id="reg-phone" placeholder="09XXXXXXXXX" inputmode="tel" class="w-full input-minimal py-3 text-white placeholder-white/30 touch-target" required>
</div>
<div>
<label class="block text-xs text-white/60 mb-2">رمز عبور</label>
<input type="password" id="reg-password" placeholder="حداقل ۴ کاراکتر" class="w-full input-minimal py-3 text-white placeholder-white/30 touch-target" required>
</div>
<button type="submit" class="w-full bg-white text-slate-900 font-bold py-3 rounded-lg hover:bg-white/90 transition-colors mt-4 touch-target active:scale-95 transform transition-transform">
ثبت نام
</button>
</form>
<div class="mt-6 text-center">
<p class="text-xs text-white/40">
ساخته شده با PHP و MySQL
</p>
</div>
</div>
</div>
<!-- Dashboard View -->
<div id="dashboard-view" class="h-full w-full flex flex-col md:flex-row relative hidden">
<!-- Mobile Sidebar Overlay -->
<div id="sidebar-overlay" class="sidebar-overlay md:hidden" onclick="toggleSidebar()"></div>
<!-- Sidebar -->
<aside id="sidebar"
class="mobile-sidebar md:relative md:transform-none md:w-72 md:h-full glass-panel border-l border-white/10 flex flex-col bg-slate-900/95 md:bg-transparent">
<!-- Profile -->
<div class="p-4 md:p-6 border-b border-white/10 flex items-center justify-between">
<div class="flex items-center gap-3 flex-1">
<div id="user-avatar" class="w-10 h-10 md:w-12 md:h-12 rounded-full flex items-center justify-center text-blue-300 font-bold text-lg">
<span id="user-avatar-initial">U</span>
</div>
<div class="flex-1 min-w-0">
<h2 id="user-name-display" class="font-bold text-sm truncate">کاربر</h2>
<p id="user-phone-display" class="text-xs text-white/50 font-mono">09123456789</p>
</div>
</div>
<button onclick="logout()" class="text-white/40 hover:text-white transition-colors p-2 touch-target mr-2">
<span style="font-size: 18px;">🚪</span>
</button>
</div>
<!-- Create Room -->
<div class="p-4 border-b border-white/10">
<div class="flex justify-between items-center mb-3">
<span class="text-xs font-medium text-white/60">اتاقهای من</span>
<span id="room-count-badge" class="text-xs bg-white/10 px-2 py-0.5 rounded-full">۰/۳</span>
</div>
<button onclick="openCreateRoomModal()" id="btn-create-room" class="w-full py-3 border border-dashed border-white/20 rounded-lg text-sm text-white/70 hover:border-white/40 hover:text-white transition-colors touch-target">
<span style="font-size: 14px;">➕</span> اتاق جدید
</button>
<p id="room-limit-msg" class="text-xs text-red-400 mt-2 hidden">حداکثر ۳ اتاق مجاز است</p>
</div>
<!-- Room List -->
<div class="flex-1 overflow-y-auto p-2 space-y-1" id="room-list-container">
<div class="text-center mt-8 text-white/30 text-sm">
<p>اتاقی وجود ندارد</p>
</div>
</div>
<!-- Mobile Safe Area -->
<div class="h-safe-bottom md:hidden"></div>
</aside>
<!-- Main Content -->
<main class="flex-1 flex flex-col h-full relative bg-slate-900/20 w-full">
<!-- Mobile Header -->
<header
class="h-14 glass-panel border-b border-white/10 flex items-center justify-between px-4 md:px-6 md:hidden">
<button onclick="toggleSidebar()" class="touch-target flex items-center justify-center w-10 h-10 -mr-2 text-white/80">
<span style="font-size: 18px;">☰</span>
</button>
<span class="text-sm font-medium text-white/60">پیام رسان مینیمال</span>
<div class="w-10"></div> <!-- Spacer for balance -->
</header>
<!-- Desktop Header -->
<header class="hidden md:flex h-14 glass-panel border-b border-white/10 items-center justify-between px-6">
<span class="text-sm font-medium text-white/60">داشبورد</span>
<div class="flex items-center gap-2 text-xs text-white/40">
<span class="w-2 h-2 bg-green-500 rounded-full animate-pulse"></span>
آنلاین
</div>
</header>
<!-- Welcome Screen -->
<div id="welcome-screen" class="flex-1 flex flex-col items-center justify-center p-8 text-center">
<div class="w-16 h-16 md:w-20 md:h-20 bg-white/5 rounded-full flex items-center justify-center mb-4">
<span style="font-size: 28px;">💬</span>
</div>
<h2 class="text-lg md:text-xl font-bold mb-2">به پیام رسان خوش آمدید</h2>
<p class="text-white/50 text-sm max-w-md">اتاق جدید بسازید یا یکی را انتخاب کنید</p>
<button onclick="openCreateRoomModal()" class="mt-6 md:hidden bg-white/10 px-6 py-3 rounded-full text-sm font-medium touch-target">
<span style="font-size: 14px;">➕</span> ساخت اتاق جدید
</button>
</div>
<!-- Chat Interface -->
<div id="chat-interface" class="hidden absolute inset-0 bg-slate-900 flex flex-col fade-in z-20">
<!-- Chat Header -->
<div class="h-14 glass-panel border-b border-white/10 flex items-center justify-between px-4 safe-top">
<div class="flex items-center gap-3 flex-1 min-w-0">
<button onclick="closeChat()" class="md:hidden text-white/60 hover:text-white touch-target w-10 h-10 flex items-center justify-center -mr-2">
<span style="font-size: 18px;">←</span>
</button>
<div
class="w-9 h-9 md:w-10 md:h-10 rounded-full bg-indigo-500/20 flex items-center justify-center shrink-0">
<span style="font-size: 14px;">#</span>
</div>
<div class="min-w-0 flex-1">
<h3 id="chat-room-name" class="font-bold text-sm truncate">اتاق</h3>
<span id="chat-user-count" class="text-xs text-white/50">۲ عضو</span>
</div>
</div>
<button onclick="openRoomSettings()" class="text-white/40 hover:text-white text-sm touch-target w-10 h-10 flex items-center justify-center">
<span style="font-size: 18px;">⚙️</span>
</button>
</div>
<!-- Messages -->
<div id="messages-container" class="flex-1 overflow-y-auto p-4 space-y-3 pb-20 md:pb-4">
<!-- Messages injected here -->
</div>
<!-- Sticker Picker -->
<div id="sticker-picker" class="sticker-picker">
<div class="sticker-category">
<div class="sticker-category-title">خنده</div>
<div class="sticker-grid">
<div class="sticker-item" onclick="insertSticker('😂')">😂</div>
<div class="sticker-item" onclick="insertSticker('😆')">😆</div>
<div class="sticker-item" onclick="insertSticker('😅')">😅</div>
<div class="sticker-item" onclick="insertSticker('🤣')">🤣</div>
<div class="sticker-item" onclick="insertSticker('😁')">😁</div>
</div>
</div>
<div class="sticker-category">
<div class="sticker-category-title">احساسات</div>
<div class="sticker-grid">
<div class="sticker-item" onclick="insertSticker('😍')">😍</div>
<div class="sticker-item" onclick="insertSticker('😘')">😘</div>
<div class="sticker-item" onclick="insertSticker('🥰')">🥰</div>
<div class="sticker-item" onclick="insertSticker('😊')">😊</div>
<div class="sticker-item" onclick="insertSticker('😢')">😢</div>
</div>
</div>
<div class="sticker-category">
<div class="sticker-category-title">دیگر</div>
<div class="sticker-grid">
<div class="sticker-item" onclick="insertSticker('👍')">👍</div>
<div class="sticker-item" onclick="insertSticker('👎')">👎</div>
<div class="sticker-item" onclick="insertSticker('❤️')">❤️</div>
<div class="sticker-item" onclick="insertSticker('🔥')">🔥</div>
<div class="sticker-item" onclick="insertSticker('🎉')">🎉</div>
</div>
</div>
</div>
<!-- Input -->
<div
class="absolute bottom-0 left-0 right-0 p-3 md:p-4 glass-panel border-t border-white/10 safe-bottom bg-slate-900/90 backdrop-blur-xl">
<form onsubmit="sendMessage(event)" class="flex gap-2 max-w-4xl mx-auto">
<button type="button" onclick="toggleStickerPicker()" class="bg-white/10 border border-white/10 rounded-full w-11 h-11 flex items-center justify-center transition-colors touch-target active:scale-95 transform shrink-0">
<span style="font-size: 18px;">😊</span>
</button>
<input type="text" id="message-input" placeholder="پیام خود را بنویسید..."
class="flex-1 bg-white/10 border border-white/10 rounded-full px-4 py-3 text-sm text-white placeholder-white/30 focus:outline-none focus:border-white/30 focus:bg-white/15 transition-all touch-target"
autocomplete="off">
<button type="submit" class="bg-blue-600 hover:bg-blue-500 text-white w-11 h-11 rounded-full flex items-center justify-center transition-colors touch-target active:scale-95 transform shadow-lg shadow-blue-600/30 shrink-0">
<span style="font-size: 18px;">📤</span>
</button>
</form>
</div>
</div>
</main>
</div>
<!-- Create Room Modal -->
<div id="create-room-modal"
class="fixed inset-0 z-50 hidden flex items-end md:items-center justify-center p-0 md:p-4 bg-black/60 backdrop-blur-sm transition-opacity">
<div
class="glass-panel w-full md:max-w-sm rounded-t-2xl md:rounded-2xl p-6 fade-in bg-slate-900 border-t md:border border-white/10">
<div class="flex justify-between items-center mb-4">
<h3 class="font-bold text-lg">اتاق جدید</h3>
<button onclick="closeCreateRoomModal()" class="text-white/40 hover:text-white touch-target w-10 h-10 flex items-center justify-center">
<span style="font-size: 20px;">✕</span>
</button>
</div>
<form onsubmit="handleCreateRoom(event)" class="space-y-4">
<div>
<label class="block text-xs text-white/60 mb-2">نام اتاق</label>
<input type="text" id="new-room-name" placeholder="مثلاً: گروه دوستان"
class="w-full bg-white/5 border border-white/10 rounded-xl px-4 py-3 text-white placeholder-white/30 focus:outline-none focus:border-white/30 touch-target"
required>
</div>
<div class="flex gap-3 pt-2">
<button type="button" onclick="closeCreateRoomModal()" class="flex-1 py-3 rounded-xl border border-white/10 text-sm hover:bg-white/5 transition-colors touch-target">
انصراف
</button>
<button type="submit" class="flex-1 py-3 rounded-xl bg-white text-slate-900 text-sm font-bold hover:bg-white/90 transition-colors touch-target active:scale-95 transform">
ساختن
</button>
</div>
</form>
</div>
</div>
<!-- Profile Edit Modal -->
<div id="profile-edit-modal" class="profile-edit-modal">
<div class="profile-edit-content">
<div class="flex justify-between items-center mb-4">
<h3 class="font-bold text-lg">ویرایش پروفایل</h3>
<button onclick="closeProfileEditModal()" class="text-white/40 hover:text-white touch-target w-10 h-10 flex items-center justify-center">
<span style="font-size: 20px;">✕</span>
</button>
</div>
<form onsubmit="saveProfile(event)" class="space-y-4">
<div>
<label class="block text-xs text-white/60 mb-2">نام کامل</label>
<input type="text" id="edit-profile-name" placeholder="نام شما"
class="w-full bg-white/5 border border-white/10 rounded-xl px-4 py-3 text-white placeholder-white/30 focus:outline-none focus:border-white/30 touch-target"
required>
</div>
<div>
<label class="block text-xs text-white/60 mb-2">رنگ آواتار</label>
<div class="avatar-grid">
<div class="avatar-option" style="background-color: #3b82f620;" onclick="selectAvatarColor('#3b82f6')">A</div>
<div class="avatar-option" style="background-color: #ef444420;" onclick="selectAvatarColor('#ef4444')">B</div>
<div class="avatar-option" style="background-color: #10b98120;" onclick="selectAvatarColor('#10b981')">C</div>
<div class="avatar-option" style="background-color: #f59e0b20;" onclick="selectAvatarColor('#f59e0b')">D</div>
<div class="avatar-option" style="background-color: #8b5cf620;" onclick="selectAvatarColor('#8b5cf6')">E</div>
<div class="avatar-option" style="background-color: #ec489920;" onclick="selectAvatarColor('#ec4899')">F</div>
<div class="avatar-option" style="background-color: #14b8a620;" onclick="selectAvatarColor('#14b8a6')">G</div>
<div class="avatar-option" style="background-color: #f9731620;" onclick="selectAvatarColor('#f97316')">H</div>
</div>
<input type="hidden" id="edit-profile-color" value="#3b82f6">
</div>
<div class="flex gap-3 pt-2">
<button type="button" onclick="closeProfileEditModal()" class="flex-1 py-3 rounded-xl border border-white/10 text-sm hover:bg-white/5 transition-colors touch-target">
انصراف
</button>
<button type="submit" class="flex-1 py-3 rounded-xl bg-white text-slate-900 text-sm font-bold hover:bg-white/90 transition-colors touch-target active:scale-95 transform">
ذخیره
</button>
</div>
</form>
</div>
</div>
<!-- Room Settings Modal -->
<div id="room-settings-modal" class="room-settings-modal">
<div class="room-settings-content">
<div class="flex justify-between items-center mb-4">
<h3 class="font-bold text-lg">تنظیمات اتاق</h3>
<button onclick="closeRoomSettingsModal()" class="text-white/40 hover:text-white touch-target w-10 h-10 flex items-center justify-center">
<span style="font-size: 20px;">✕</span>
</button>
</div>
<form onsubmit="updateRoomSettings(event)" class="space-y-4">
<div>
<label class="block text-xs text-white/60 mb-2">نام اتاق</label>
<input type="text" id="edit-room-name" placeholder="نام اتاق"
class="w-full bg-white/5 border border-white/10 rounded-xl px-4 py-3 text-white placeholder-white/30 focus:outline-none focus:border-white/30 touch-target"
required>
</div>
<div>
<label class="block text-xs text-white/60 mb-2">رنگ آواتار اتاق</label>
<div class="avatar-grid">
<div class="avatar-option" style="background-color: #3b82f620;" onclick="selectRoomColor('#3b82f6')">#</div>
<div class="avatar-option" style="background-color: #ef444420;" onclick="selectRoomColor('#ef4444')">#</div>
<div class="avatar-option" style="background-color: #10b98120;" onclick="selectRoomColor('#10b981')">#</div>
<div class="avatar-option" style="background-color: #f59e0b20;" onclick="selectRoomColor('#f59e0b')">#</div>
<div class="avatar-option" style="background-color: #8b5cf620;" onclick="selectRoomColor('#8b5cf6')">#</div>
<div class="avatar-option" style="background-color: #ec489920;" onclick="selectRoomColor('#ec4899')">#</div>
<div class="avatar-option" style="background-color: #14b8a620;" onclick="selectRoomColor('#14b8a6')">#</div>
<div class="avatar-option" style="background-color: #f9731620;" onclick="selectRoomColor('#f97316')">#</div>
</div>
<input type="hidden" id="edit-room-color" value="#3b82f6">
</div>
<div class="danger-zone">
<h4 class="text-xs font-medium text-red-400 mb-2">منطقه خطر</h4>
<button type="button" onclick="confirmDeleteRoom()" class="w-full py-3 rounded-xl text-sm font-medium transition-colors touch-target danger-button">
حذف اتاق
</button>
</div>
<div class="flex gap-3 pt-2">
<button type="button" onclick="closeRoomSettingsModal()" class="flex-1 py-3 rounded-xl border border-white/10 text-sm hover:bg-white/5 transition-colors touch-target">
انصراف
</button>
<button type="submit" class="flex-1 py-3 rounded-xl bg-white text-slate-900 text-sm font-bold hover:bg-white/90 transition-colors touch-target active:scale-95 transform">
ذخیره
</button>
</div>
</form>
</div>
</div>
<!-- Confirmation Modal -->
<div id="confirm-modal" class="profile-edit-modal">
<div class="profile-edit-content">
<div class="flex justify-between items-center mb-4">
<h3 class="font-bold text-lg" id="confirm-title">تایید حذف</h3>
<button onclick="closeConfirmModal()" class="text-white/40 hover:text-white touch-target w-10 h-10 flex items-center justify-center">
<span style="font-size: 20px;">✕</span>
</button>
</div>
<p id="confirm-message" class="mb-6">آیا مطمئن هستید که میخواهید این اتاق را حذف کنید؟ این عمل قابل بازگشت نیست.</p>
<div class="flex gap-3">
<button onclick="closeConfirmModal()" class="flex-1 py-3 rounded-xl border border-white/10 text-sm hover:bg-white/5 transition-colors touch-target">
انصراف
</button>
<button onclick="executeConfirmedAction()" class="flex-1 py-3 rounded-xl bg-red-600 text-white text-sm font-bold hover:bg-red-500 transition-colors touch-target active:scale-95 transform">
حذف
</button>
</div>
</div>
</div>
<script>
// ========== Global Variables ==========
let currentUser = {
id: 1,
name: "کاربر تست",
phone: "09123456789",
avatar_color: "#3b82f6"
};
let currentRoomId = null;
let isSidebarOpen = false;
let messagePollInterval = null;
let stickerPickerOpen = false;
let pendingAction = null;
// ========== Helper Functions ==========
// Show toast notification
function showToast(message, type = 'info') {
const container = document.getElementById('toast-container');
const toast = document.createElement('div');
let bgClass = 'bg-white/10';
let icon = 'ℹ️';
if (type === 'success') { bgClass = 'bg-green-500/20 text-green-200 border border-green-500/30'; icon = '✅'; }
if (type === 'error') { bgClass = 'bg-red-500/20 text-red-200 border border-red-500/30'; icon = '❌'; }
toast.className = `${bgClass} px-4 py-3 rounded-xl flex items-center gap-3 text-sm backdrop-blur-md fade-in shadow-lg`;
toast.innerHTML = `<span>${icon}</span><span class="font-medium">${message}</span>`;
container.appendChild(toast);
setTimeout(() => {
toast.style.opacity = '0';
toast.style.transform = 'translateY(-10px)';
setTimeout(() => toast.remove(), 300);
}, 3000);
}
// Simulate API call
async function apiCall(endpoint, data = null, method = 'POST') {
// Simulate network delay
await new Promise(resolve => setTimeout(resolve, 300));
// Mock responses for demo purposes
if (endpoint.includes('auth.php?action=login')) {
return {
success: true,
message: "ورود موفقیتآمیز بود",
data: {
id: 1,
name: data.phone === "09123456789" ? "کاربر تست" : "کاربر جدید",
phone: data.phone,
avatar_color: "#3b82f6"
}
};
}
if (endpoint.includes('auth.php?action=register')) {
return {
success: true,
message: "ثبتنام موفقیتآمیز بود",
data: {
id: 2,
name: data.name,
phone: data.phone,
avatar_color: "#" + Math.floor(Math.random()*16777215).toString(16)
}
};
}
if (endpoint.includes('rooms.php?action=list')) {
return {
success: true,
data: {
created_rooms: [
{ id: 1, name: "گروه دوستان", creator_id: 1, member_count: 3 },
{ id: 2, name: "گروه خانواده", creator_id: 1, member_count: 5 }
],
member_rooms: [
{ id: 3, name: "گروه کاری", creator_id: 2, member_count: 8 }
],
created_count: 2
}
};
}
if (endpoint.includes('rooms.php?action=create')) {
return {
success: true,
message: "اتاق با موفقیت ایجاد شد",
data: {
id: Math.floor(Math.random() * 1000) + 3,
name: data.name,
creator_id: currentUser.id,
member_count: 1
}
};
}
if (endpoint.includes('rooms.php?action=get')) {
return {
success: true,
data: {
id: parseInt(endpoint.split('=')[1]),
name: "اتاق تست",
creator_id: currentUser.id,
member_count: 3,
avatar_color: "#3b82f6"
}
};
}
if (endpoint.includes('messages.php?action=get')) {
return {
success: true,
data: [
{ id: 1, room_id: 1, user_id: 1, sender_name: "کاربر تست", message: "سلام به همه!", created_at: "2023-05-15 10:30:00" },
{ id: 2, room_id: 1, user_id: 2, sender_name: "کاربر دیگر", message: "سلام! چطوری؟", created_at: "2023-05-15 10:32:00" },
{ id: 3, room_id: 1, user_id: 1, sender_name: "کاربر تست", message: "خوبم ممنون! 😊", created_at: "2023-05-15 10:33:00" }
]
};
}
if (endpoint.includes('messages.php?action=send')) {
return {
success: true,
data: {
id: Math.floor(Math.random() * 1000) + 10,
room_id: data.room_id,
user_id: currentUser.id,
sender_name: currentUser.name,
message: data.message,
created_at: new Date().toISOString()
}
};
}
if (endpoint.includes('auth.php?action=logout')) {
return { success: true };
}
if (endpoint.includes('rooms.php?action=delete')) {
return { success: true, message: "اتاق با موفقیت حذف شد" };
}
if (endpoint.includes('rooms.php?action=update')) {
return { success: true, message: "اتاق با موفقیت بهروزرسانی شد" };
}
if (endpoint.includes('profile.php?action=update')) {
return { success: true, message: "پروفایل با موفقیت بهروزرسانی شد" };
}
return { success: false, message: "خطا در ارتباط با سرور" };
}
// Escape HTML
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
// Scroll to bottom of messages
function scrollToBottom() {
const container = document.getElementById('messages-container');
if (container) {
container.scrollTop = container.scrollHeight;
}
}
// Check if user is near bottom of messages
function isUserNearBottom() {
const container = document.getElementById('messages-container');
if (!container) return false;
const threshold = 100;
return container.scrollHeight - container.scrollTop - container.clientHeight < threshold;
}
// ========== Auth Functions ==========
async function handleRegister(e) {
e.preventDefault();
const name = document.getElementById('reg-name').value.trim();
const phone = document.getElementById('reg-phone').value.trim();
const password = document.getElementById('reg-password').value;
if (phone.length < 11) {
showToast('شماره موبایل صحیح نیست', 'error');
return;
}
try {
const result = await apiCall('auth.php?action=register', {
name: name,
phone: phone,
password: password
});
showToast(result.message, 'success');
// Simulate login after registration
currentUser = result.data;
document.getElementById('auth-view').classList.add('hidden');
document.getElementById('dashboard-view').classList.remove('hidden');
updateUserProfile();
await renderRoomList();
} catch (error) {
showToast(error.message || 'خطا در ثبتنام', 'error');
}
}
async function handleLogin(e) {
e.preventDefault();
const phone = document.getElementById('login-phone').value.trim();
const password = document.getElementById('login-password').value;
try {
const result = await apiCall('auth.php?action=login', {
phone: phone,
password: password
});
currentUser = result.data;
document.getElementById('auth-view').classList.add('hidden');
document.getElementById('dashboard-view').classList.remove('hidden');
updateUserProfile();
await renderRoomList();
showToast(`خوش آمدید ${result.data.name}`, 'success');
} catch (error) {
showToast(error.message || 'خطا در ورود', 'error');
}
}
async function logout() {
try {
await apiCall('auth.php?action=logout');
document.getElementById('dashboard-view').classList.add(' |