{"version":3,"file":"chat_controller-CLRvVQqI.js","sources":["../../../app/javascript/controllers/chat_controller.js"],"sourcesContent":["import ApplicationController from \"./application_controller\"\n\nexport default class extends ApplicationController {\n static targets = [\n \"input\",\n \"submitButton\",\n \"composeForm\",\n \"composeInput\",\n \"voiceContainer\",\n \"templates\",\n \"scrollToBottom\",\n \"inbox\"\n ]\n\n static values = {\n url: String,\n page: Number,\n translations: Object\n }\n\n initialize() {\n super.initialize()\n\n this.observer = new IntersectionObserver(this.callback.bind(this), {\n threshold: 1,\n rootMargin: \"0px\"\n })\n }\n\n attemptSendMessage(e) {\n if(document.querySelectorAll(\"[data-uploading]\").length > 0) {\n e.preventDefault()\n\n this.showToastErrorMessage(this.translationsValue.attachmentUploading)\n return\n }\n\n if(document.querySelectorAll(\"[data-upload-error]\").length > 0) {\n e.preventDefault()\n this.showToastErrorMessage(this.translationsValue.attachmentUploadError)\n\n return\n }\n\n if (!this.hasLocation && !this.voiceMessage && this.inputTarget.value.trim().length === 0 && document.querySelectorAll(\"[data-uploaded]\").length === 0) {\n e.preventDefault()\n\n this.addClass(this.inputTarget.parentElement, \"border-red-500\")\n this.removeClass(this.inputTarget.parentElement, \"focus-within:border-tiger\", \"focus-within:ring-1\", \"ring-tiger\")\n }\n\n if (e.target !== this.submitButtonTarget) {\n this.submitButtonTarget.click()\n e.preventDefault()\n }\n }\n\n sync(e) {\n if (\n this.inputTarget.parentElement.classList.contains(\"border-red-500\") &&\n this.inputTarget.value.trim().length !== 0\n ) {\n this.removeClass(this.inputTarget.parentElement, \"border-red-500\")\n this.addClass(this.inputTarget.parentElement, \"focus-within:border-tiger\", \"focus-within:ring-1\", \"ring-tiger\")\n }\n\n if (!e.shiftKey && e.key === \"Enter\") {\n if(this.templatesTarget.hasAttribute('data-visible') && this.inputTarget.value.trim() === '/') {\n e.preventDefault()\n e.stopPropagation()\n\n this.dispatch('templates:enter', {\n target: this.templatesTarget,\n })\n\n return\n }\n\n this.attemptSendMessage(e)\n e.stopImmediatePropagation()\n }\n }\n\n onKeyUp(e) {\n const value = e.target.textContent\n\n console.log(\"value\", value)\n\n if(value.trim().startsWith(\"/\")) {\n this.dispatch(\"templates:show\", {\n target: document.documentElement,\n detail: value.trim().split(\"/\")[1]\n })\n } else {\n this.dispatch(\"templates:hide\", {\n target: document.documentElement,\n })\n }\n }\n\n focusNote() {\n this.nextTick(() => {\n this.dispatch(\"note:focus\", {\n target: document.documentElement,\n })\n }, 100)\n }\n\n focusCompose({ detail }) {\n this.dispatch(\"note:blur\", {\n target: document.documentElement,\n })\n\n const option = document.querySelector(`[data-element-id='${detail}']`)\n\n if(option) {\n option.dataset.action = option.dataset.action.split(\" \").filter(action => action !== \"click->custom-dropdown#toggle\").join(\" \")\n option.click()\n setTimeout(() => {\n option.dataset.action = [\"click->custom-dropdown#toggle\", ...option.dataset.action.split(\" \")].join(\" \")\n }, 1)\n } else {\n\n this.dispatch('focus', {\n target: document.documentElement\n })\n }\n }\n\n focusMessage({ currentTarget }) {\n const messageContentElement = window.document.getElementById(currentTarget.dataset.messageId)\n this.observer.observe(messageContentElement)\n messageContentElement.scrollIntoView({ behavior: \"smooth\", block: \"nearest\" })\n }\n\n focusCampaignMessage({ detail: messageId }) {\n console.log('in here', messageId)\n const messageContentElement = window.document.getElementById(messageId)\n this.observer.observe(messageContentElement)\n messageContentElement.scrollIntoView({ behavior: \"smooth\", block: \"nearest\" })\n }\n\n callback(entries, observer) {\n entries.forEach(entry => {\n\n if (entry.isIntersecting) {\n const parentElement = entry.target.closest(\"[data-flashable]\")\n\n if(parentElement.dataset.type === \"vcard\") {\n this.dispatch(\"flash-message\", {\n target: parentElement,\n detail: { id: parentElement.id }\n })\n } else {\n const chatHead = parentElement.querySelector(\"[data-message-target='chatHead']\")\n\n const containerClass = parentElement.dataset.messageState === \"received\" ? \"bg-lavender-light\" : \"bg-night-10\"\n const chatHeadClass = parentElement.dataset.messageState === \"received\" ? \"fill-lavender-light\" : \"fill-night-10\"\n\n entry.target.classList.replace(containerClass, \"bg-lavender\")\n\n if(chatHead) {\n chatHead.classList.replace(chatHeadClass, \"fill-lavender\")\n }\n\n setTimeout(() => {\n entry.target.classList.replace(\"bg-lavender\", containerClass)\n\n if(chatHead) {\n chatHead.classList.replace(\"fill-lavender\", chatHeadClass)\n }\n }, 500)\n }\n\n\n observer.unobserve(entry.target);\n }\n });\n }\n\n scrollToBottomTargetConnected() {\n this.inboxTarget.scroll({\n top: this.inboxTarget.scrollHeight,\n behavior: \"smooth\"\n })\n\n this.scrollToBottomTarget.remove()\n }\n\n get hasLocation() {\n return this.locationInputs.filter(location => location.value).length > 0\n }\n\n get locationInputs() {\n return Array.from(this.element.querySelectorAll(\"input[data-google-map-target]\"))\n }\n\n get voiceMessage() {\n return this.voiceContainerTarget.children.length > 0\n }\n}\n"],"names":["chat_controller","ApplicationController","e","value","detail","option","action","currentTarget","messageContentElement","messageId","entries","observer","entry","parentElement","chatHead","containerClass","chatHeadClass","location","__publicField"],"mappings":"uNAEe,MAAKA,UAASC,CAAsB,CAkBjD,YAAa,CACX,MAAM,WAAU,EAEhB,KAAK,SAAW,IAAI,qBAAqB,KAAK,SAAS,KAAK,IAAI,EAAG,CACjE,UAAW,EACX,WAAY,KACb,CAAA,CACL,CAEE,mBAAmBC,EAAG,CACpB,GAAG,SAAS,iBAAiB,kBAAkB,EAAE,OAAS,EAAG,CAC3DA,EAAE,eAAc,EAEhB,KAAK,sBAAsB,KAAK,kBAAkB,mBAAmB,EACrE,MACN,CAEI,GAAG,SAAS,iBAAiB,qBAAqB,EAAE,OAAS,EAAG,CAC9DA,EAAE,eAAc,EAChB,KAAK,sBAAsB,KAAK,kBAAkB,qBAAqB,EAEvE,MACN,CAEQ,CAAC,KAAK,aAAe,CAAC,KAAK,cAAgB,KAAK,YAAY,MAAM,KAAI,EAAG,SAAW,GAAK,SAAS,iBAAiB,iBAAiB,EAAE,SAAW,IACnJA,EAAE,eAAc,EAEhB,KAAK,SAAS,KAAK,YAAY,cAAe,gBAAgB,E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