SideBar.svelte 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 } 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. break;
  46. }
  47. });
  48. function handleLogout() {
  49. localStorage.removeItem('flag');
  50. localStorage.removeItem('token');
  51. goto('/login');
  52. }
  53. function navigate(path) {
  54. goto(path);
  55. isMobileMenuOpen = false;
  56. }
  57. $: currentPath = get(page).url.pathname;
  58. </script>
  59. <div class="flex h-screen bg-gray-900 text-white">
  60. <div class="hidden w-64 flex-col border-r border-gray-700 bg-gray-800 md:flex">
  61. <div class=" flex h-16 items-center justify-center border-b border-gray-700">
  62. <img src={$logo_id} alt="Logo" class="mr-2 h-8 w-8" />
  63. <h1 class="text-xl font-semibold">Bar do Ferlin</h1>
  64. </div>
  65. <div class="flex flex-1 flex-col overflow-y-auto">
  66. <nav class="flex-1 space-y-2 px-2 py-4">
  67. {#each navItems as item}
  68. <button
  69. class={`flex cursor-pointer items-center rounded-lg px-4 py-3 text-sm transition-colors ${
  70. currentPath === item.path
  71. ? 'bg-gray-700 text-white'
  72. : 'text-gray-300 hover:bg-gray-700'
  73. }`}
  74. onclick={() => goto(item.path)}
  75. >
  76. <img
  77. src="../src/lib/assets/{item.icon.toLowerCase()}.svg"
  78. class="h-6 w-6"
  79. alt={item.name}
  80. />
  81. <span class="ml-3">{item.name}</span>
  82. </button>
  83. {/each}
  84. </nav>
  85. </div>
  86. <div class="border-t border-gray-700 p-4">
  87. <button
  88. 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"
  89. onclick={handleLogout}
  90. >
  91. <img src={logout_icon} class="mr-2 h-5 w-5" alt="Logout" />
  92. <span>Sair</span>
  93. </button>
  94. </div>
  95. </div>
  96. <!-- Header Mobile -->
  97. <div class="flex flex-1 flex-col">
  98. <header
  99. 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"
  100. >
  101. <div class="flex items-center">
  102. <button
  103. class="mr-4 rounded-md p-1 text-gray-400 hover:text-white"
  104. onclick={() => (isMobileMenuOpen = !isMobileMenuOpen)}
  105. >
  106. {#if isMobileMenuOpen}
  107. <img src={close_icon} class="h-6 w-6" alt="Fechar" />
  108. {:else}
  109. <img src={menu_icon} class="h-6 w-6" alt="Menu" />
  110. {/if}
  111. </button>
  112. <div class="flex items-center">
  113. <img src={beer_green} class="mr-2 h-7 w-7 text-emerald-500" alt="Logo" />
  114. <h1 class="text-lg font-semibold">Bar do Ferlin</h1>
  115. </div>
  116. </div>
  117. </header>
  118. <!-- Mobile Menu -->
  119. {#if isMobileMenuOpen}
  120. <div class="absolute inset-x-0 top-16 z-20 border-b border-gray-700 bg-gray-800 md:hidden">
  121. <nav class="flex flex-col space-y-2 p-4">
  122. {#each navItems as item}
  123. <button
  124. class={`flex items-center rounded-lg px-4 py-3 text-sm transition-colors ${
  125. currentPath === item.path
  126. ? 'bg-gray-700 text-white'
  127. : 'text-gray-300 hover:bg-gray-700'
  128. }`}
  129. onclick={() => navigate(item.path)}
  130. >
  131. <img
  132. src="../src/lib/assets/{item.icon.toLowerCase()}.svg"
  133. class="h-6 w-6"
  134. alt={item.name}
  135. />
  136. <span class="ml-3">{item.name}</span>
  137. </button>
  138. {/each}
  139. <button
  140. class="flex cursor-pointer items-center rounded-lg px-4 py-3 text-sm text-red-400 transition-colors hover:bg-gray-700"
  141. onclick={handleLogout}
  142. >
  143. <img src={logout_icon} class="mr-2 h-5 w-5" alt="Logout" />
  144. <span>Sair</span>
  145. </button>
  146. </nav>
  147. </div>
  148. {/if}
  149. <!-- Main Content -->
  150. <main class="flex-1 overflow-y-auto bg-gray-900 p-6 px-4 sm:px-6">
  151. <slot />
  152. </main>
  153. </div>
  154. </div>