SellMenu.svelte 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <script>
  2. import { createEventDispatcher } from 'svelte';
  3. import { fly, fade } from 'svelte/transition';
  4. export let isOpen = false;
  5. export let onClose = () => {};
  6. export let onConfirm = (payload) => {};
  7. export let rateBRLPerEasyCoin = 1;
  8. const dispatch = createEventDispatcher();
  9. let pixKey = '';
  10. let amount = '';
  11. $: numericAmount = Number(amount) || 0;
  12. $: totalBRL = numericAmount * Number(rateBRLPerEasyCoin || 1);
  13. function close() {
  14. onClose();
  15. dispatch('close');
  16. }
  17. function confirm() {
  18. if (!pixKey || !numericAmount) return;
  19. const payload = { pixKey, amount: numericAmount, totalBRL };
  20. onConfirm(payload);
  21. dispatch('confirm', payload);
  22. }
  23. function formatBRL(n) {
  24. return new Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(Number(n || 0));
  25. }
  26. </script>
  27. {#if isOpen}
  28. <div class="fixed inset-0 z-50" aria-modal="true" role="dialog" aria-label="Vender EasyCoin">
  29. <div
  30. class="absolute inset-0 bg-black/40"
  31. role="button"
  32. tabindex="0"
  33. aria-label="Fechar menu de venda"
  34. on:click={close}
  35. on:keydown={(event) => {
  36. if (event.key === 'Enter' || event.key === ' ') {
  37. event.preventDefault();
  38. close();
  39. }
  40. }}
  41. transition:fade
  42. ></div>
  43. <div
  44. class="absolute inset-y-0 right-0 w-full max-w-md bg-white dark:bg-gray-900 border-l border-gray-200 dark:border-gray-700 shadow-xl flex flex-col"
  45. transition:fly={{ x: 24, duration: 200 }}
  46. >
  47. <div class="px-6 py-4 border-b border-gray-200 dark:border-gray-700 flex items-center justify-between">
  48. <h3 class="text-lg font-semibold text-gray-900 dark:text-gray-100">Vender EasyCoin</h3>
  49. <button
  50. class="text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200"
  51. aria-label="Fechar"
  52. on:click={close}
  53. >
  54. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
  55. fill="none" stroke="currentColor" stroke-width="1.5" class="w-5 h-5">
  56. <path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
  57. </svg>
  58. </button>
  59. </div>
  60. <div class="p-6 space-y-4 overflow-auto">
  61. <div class="rounded-lg border border-amber-200 bg-amber-50 text-amber-900 px-4 py-3 text-sm">
  62. <p class="font-semibold">Função não implementada ainda</p>
  63. <p>
  64. Este formulário permite simular a venda e preencher os campos (PIX e quantidade),
  65. mas o envio ainda não está conectado ao backend/pagamentos reais.
  66. </p>
  67. </div>
  68. <div class="space-y-1">
  69. <label class="block text-sm font-medium text-gray-700 dark:text-gray-300" for="sell-pix-key">Chave Pix</label>
  70. <input
  71. id="sell-pix-key"
  72. class="w-full px-3 py-2 rounded-md bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500"
  73. bind:value={pixKey}
  74. placeholder="Informe sua chave Pix" />
  75. </div>
  76. <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
  77. <div class="space-y-1">
  78. <label class="block text-sm font-medium text-gray-700 dark:text-gray-300" for="sell-amount">Quantidade (EasyCoin)</label>
  79. <input
  80. id="sell-amount"
  81. type="number" min="0" step="0.01"
  82. class="w-full px-3 py-2 rounded-md bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500"
  83. bind:value={amount}
  84. placeholder="0,00" />
  85. </div>
  86. <div class="space-y-1">
  87. <p class="block text-sm font-medium text-gray-700 dark:text-gray-300">Valor em Reais</p>
  88. <div class="w-full px-3 py-2 rounded-md bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 text-gray-900 dark:text-gray-100">
  89. {formatBRL(totalBRL)}
  90. </div>
  91. </div>
  92. </div>
  93. <div class="text-xs text-gray-500 dark:text-gray-400">
  94. Taxa de conversão: 1 EasyCoin = {formatBRL(rateBRLPerEasyCoin)}
  95. </div>
  96. </div>
  97. <div class="px-6 py-4 border-t border-gray-200 dark:border-gray-700 flex items-center justify-end gap-3">
  98. <button
  99. class="px-4 py-2 rounded-md border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 hover:bg-gray-50 dark:hover:bg-gray-700 text-gray-800 dark:text-gray-100"
  100. on:click={close}
  101. >
  102. Cancelar
  103. </button>
  104. <button
  105. class="px-4 py-2 rounded-md bg-blue-600 hover:bg-blue-700 text-white disabled:opacity-50"
  106. disabled={!pixKey || !numericAmount}
  107. on:click={confirm}
  108. >
  109. Confirmar
  110. </button>
  111. </div>
  112. </div>
  113. </div>
  114. {/if}