SideBar.svelte 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <script>
  2. import { page } from '$app/stores';
  3. import { goto } from '$app/navigation';
  4. import { get } from 'svelte/store';
  5. import { onMount } from 'svelte';
  6. import beer_green from '$lib/assets/beer_green.svg';
  7. import logout_icon from '$lib/assets/logout_icon.svg';
  8. import close_icon from '$lib/assets/close_icon.svg';
  9. import menu_icon from '$lib/assets/menu_icon.svg';
  10. import { browser } from '$app/environment';
  11. import { logo_id, companyName_id } from '$lib/utils/store';
  12. let flag = null;
  13. let company;
  14. if (browser) {
  15. flag = localStorage.getItem('flag');
  16. company = localStorage.getItem('company');
  17. }
  18. $: navItems = [];
  19. let isMobileMenuOpen = false;
  20. onMount(() => {
  21. if (flag == 'waiter') {
  22. navItems = [{ name: 'Mesas', path: '/dashboard/tables', icon: 'table_bar' }];
  23. } else if (flag == 'admin') {
  24. navItems = [
  25. { name: 'Mesas', path: '/dashboard/tables', icon: 'table_bar' },
  26. { name: 'Produtos', path: '/dashboard/products', icon: 'product_sell' },
  27. { name: 'Relatórios', path: '/dashboard/reports', icon: 'report_icon' },
  28. { name: 'Cozinha', path: '/dashboard/kitchen', icon: 'kitchen_icon' },
  29. { name: 'Gerenciar Usuários', path: '/dashboard/mananger', icon: 'mananger' }
  30. ];
  31. } else if (flag == 'kitchen') {
  32. navItems = [{ name: 'Cozinha', path: '/dashboard/kitchen', icon: 'kitchen_icon' }];
  33. } else if (flag == 'cashier') {
  34. navItems = [
  35. { name: 'Mesas', path: '/dashboard/tables', icon: 'table_bar' },
  36. { name: 'Relatórios', path: '/dashboard/reports', icon: 'report_icon' },
  37. { name: 'Cozinha', path: '/dashboard/kitchen', icon: 'kitchen_icon' }
  38. ];
  39. }
  40. switch (company) {
  41. case '1':
  42. logo_id.set(
  43. 'https://i.postimg.cc/bNNBcTZj/Whats-App-Image-2025-07-29-at-19-59-16-removebg-preview.png'
  44. );
  45. companyName_id.set('Bar do Ferlin');
  46. break;
  47. default:
  48. logo_id.set(
  49. 'https://i.postimg.cc/7LPJk38W/beer-meal-24dp-EAC452-FILL0-wght400-GRAD0-opsz24.png'
  50. );
  51. companyName_id.set('Bar Management');
  52. break;
  53. }
  54. });
  55. function handleLogout() {
  56. localStorage.removeItem('flag');
  57. localStorage.removeItem('token');
  58. localStorage.removeItem('tktime');
  59. goto('/login');
  60. }
  61. function navigate(path) {
  62. goto(path);
  63. isMobileMenuOpen = false;
  64. }
  65. $: currentPath = get(page).url.pathname;
  66. </script>
  67. <div class="flex h-screen bg-gray-900 text-white">
  68. <div class="hidden w-64 flex-col border-r border-gray-700 bg-gray-800 md:flex">
  69. <div class=" flex h-16 items-center justify-center border-b border-gray-700">
  70. <img src={$logo_id} alt="Logo" class="mr-2 h-8 w-8" />
  71. <h1 class="text-xl font-semibold">{$companyName_id}</h1>
  72. </div>
  73. <div class="flex flex-1 flex-col overflow-y-auto">
  74. <nav class="flex-1 space-y-2 px-2 py-4">
  75. {#each navItems as item}
  76. <button
  77. class={`flex cursor-pointer items-center rounded-lg px-4 py-3 text-sm transition-colors ${
  78. currentPath === item.path
  79. ? 'bg-gray-700 text-white'
  80. : 'text-gray-300 hover:bg-gray-700'
  81. }`}
  82. onclick={() => goto(item.path)}
  83. >
  84. <img
  85. src="../src/lib/assets/{item.icon.toLowerCase()}.svg"
  86. class="h-6 w-6"
  87. alt={item.name}
  88. />
  89. <span class="ml-3">{item.name}</span>
  90. </button>
  91. {/each}
  92. </nav>
  93. </div>
  94. <div class="border-t border-gray-700 p-4">
  95. <button
  96. class="flex w-full cursor-pointer items-center justify-center rounded-lg px-4 py-2 text-sm text-red-400 transition-colors hover:bg-gray-700"
  97. onclick={handleLogout}
  98. >
  99. <img src={logout_icon} class="mr-2 h-5 w-5" alt="Logout" />
  100. <span>Sair</span>
  101. </button>
  102. </div>
  103. </div>
  104. <!-- Header Mobile -->
  105. <div class="flex flex-1 flex-col">
  106. <header
  107. class="sticky top-0 z-10 flex h-16 items-center justify-between border-b border-gray-700 bg-gray-800 px-6 md:hidden"
  108. >
  109. <div class="flex items-center">
  110. <button
  111. class="mr-4 rounded-md p-1 text-gray-400 hover:text-white"
  112. onclick={() => (isMobileMenuOpen = !isMobileMenuOpen)}
  113. >
  114. {#if isMobileMenuOpen}
  115. <img src={close_icon} class="h-6 w-6" alt="Fechar" />
  116. {:else}
  117. <img src={menu_icon} class="h-6 w-6" alt="Menu" />
  118. {/if}
  119. </button>
  120. <div class="flex items-center">
  121. <img src={$logo_id} class="mr-2 h-7 w-7 text-emerald-500" alt="Logo" />
  122. <h1 class="text-lg font-semibold">Bar do Ferlin</h1>
  123. </div>
  124. </div>
  125. </header>
  126. <!-- Mobile Menu -->
  127. {#if isMobileMenuOpen}
  128. <div class="absolute inset-x-0 top-16 z-20 border-b border-gray-700 bg-gray-800 md:hidden">
  129. <nav class="flex flex-col space-y-2 p-4">
  130. {#each navItems as item}
  131. <button
  132. class={`flex items-center rounded-lg px-4 py-3 text-sm transition-colors ${
  133. currentPath === item.path
  134. ? 'bg-gray-700 text-white'
  135. : 'text-gray-300 hover:bg-gray-700'
  136. }`}
  137. onclick={() => navigate(item.path)}
  138. >
  139. <img
  140. src="../src/lib/assets/{item.icon.toLowerCase()}.svg"
  141. class="h-6 w-6"
  142. alt={item.name}
  143. />
  144. <span class="ml-3">{item.name}</span>
  145. </button>
  146. {/each}
  147. <button
  148. class="flex cursor-pointer items-center rounded-lg px-4 py-3 text-sm text-red-400 transition-colors hover:bg-gray-700"
  149. onclick={handleLogout}
  150. >
  151. <img src={logout_icon} class="mr-2 h-5 w-5" alt="Logout" />
  152. <span>Sair</span>
  153. </button>
  154. </nav>
  155. </div>
  156. {/if}
  157. <!-- Main Content -->
  158. <main class="flex-1 overflow-y-auto bg-gray-900 p-6 px-4 sm:px-6">
  159. <slot />
  160. </main>
  161. </div>
  162. </div>