{"version":3,"file":"openAiFile.min.js","names":["openAiFile","widget","document","getElementById","bannerStep","querySelector","bannerText","bannerTextCMS","bannerTextScreen1","getAttribute","bannerTextScreen2","spinner","fieldGroup","responseDiv","submit","fileSelector","fileInput","uploadedFileNameContainer","uploadedFileName","resetFileUpload","restartButton","statusDiv","apiUrl","apiSubKey","eventHandlers","addEventListener","e","preventDefault","classList","remove","click","files","length","fileName","name","innerHTML","async","event","toggleStep","uploadMessage","add","resetDefaults","scrollToWidget","elementPosition","getBoundingClientRect","top","window","scrollY","scrollTo","behavior","step1","step2","toggle","calculateBannerProgress","totalBannerSteps","progress","stepWidth","parseInt","style","width","value","file","formData","FormData","response","append","fetch","method","body","headers","ok","errorText","text","Error","status","messageContent","messageData","messages","console","error","messageGroup","message","type","marked","parse","extractAndFormatMessage","json","init","endpointSpan","textContent","subKeySpan","getApiDetails"],"sources":["openAi/openAiFile.js"],"mappings":"AAAA,MAAMA,WAAa,WAClB,MAAMC,EAASC,SAASC,eAAe,wBACjCC,EAAaH,EAAOI,cAAc,0DAClCC,EAAaL,EAAOI,cAAc,gDAClCE,EAAgBL,SAASC,eAAe,eACxCK,EAAoBD,EAAcE,aAAa,sBAC/CC,EAAoBH,EAAcE,aAAa,sBAE/CE,EAAUV,EAAOI,cAAc,2CAC/BO,EAAaX,EAAOI,cAAc,+CAClCQ,EAAcZ,EAAOI,cAAc,iBACnCS,EAASb,EAAOI,cAAc,cAC9BU,EAAed,EAAOI,cAAc,iBACpCW,EAAYf,EAAOI,cAAc,eACjCY,EAA4BhB,EAAOI,cAAc,8BACjDa,EAAmBjB,EAAOI,cAAc,qBACxCc,EAAkBlB,EAAOI,cAAc,oBACvCe,EAAgBnB,EAAOI,cAAc,uBACrCgB,EAAYpB,EAAOI,cAAc,WAEvC,IAAIiB,EACAC,EAiBJ,MAAMC,EAAgB,KACrBT,EAAaU,iBAAiB,SAASC,IACtCA,EAAEC,iBACFf,EAAWgB,UAAUC,OAAO,sBAC5Bb,EAAUc,OA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DACnD,MAAMC,EAAaxF,SAASC,eAAe,WAC3CoB,EAAYmE,EAAaA,EAAWD,YAAc,EACnD,CARCE,EAAe,EAwKhB,CApMkB,GAsMnBzF,SAASuB,iBAAiB,oBAAoB,KAC7CzB,WAAWuF,MAAM","ignoreList":[],"sourcesContent":["const openAiFile = (function () {\r\n\tconst widget = document.getElementById('parking-signs-widget');\r\n\tconst bannerStep = widget.querySelector('.parking-signs-widget__banner .banner-current-progress');\r\n\tconst bannerText = widget.querySelector('.parking-signs-widget__banner__header__title');\r\n\tconst bannerTextCMS = document.getElementById('banner-text');\r\n\tconst bannerTextScreen1 = bannerTextCMS.getAttribute('data-banner-text-1');\r\n\tconst bannerTextScreen2 = bannerTextCMS.getAttribute('data-banner-text-2');\r\n\tconst totalBannerSteps = 2;\r\n\tconst spinner = widget.querySelector('.parking-signs-widget__response-spinner');\r\n\tconst fieldGroup = widget.querySelector('#parking-signs-widget__step--1 .field-group');\r\n\tconst responseDiv = widget.querySelector('#chatResponse');\r\n\tconst submit = widget.querySelector('#btnSubmit');\r\n\tconst fileSelector = widget.querySelector('#fileSelector');\r\n\tconst fileInput = widget.querySelector('#fileUpload');\r\n\tconst uploadedFileNameContainer = widget.querySelector('#uploadedFileNameContainer');\r\n\tconst uploadedFileName = widget.querySelector('#uploadedFileName');\r\n\tconst resetFileUpload = widget.querySelector('#resetFileUpload');\r\n\tconst restartButton = widget.querySelector('#parking-btnRestart');\r\n\tconst statusDiv = widget.querySelector('#status');\r\n\r\n\tlet apiUrl;\r\n\tlet apiSubKey;\r\n\r\n\tconst init = () => {\r\n\t\tbannerStep.innerHTML = 1;\r\n\t\tbannerText.innerHTML = bannerTextScreen1;\r\n\t\teventHandlers();\r\n\t\tcalculateBannerProgress(totalBannerSteps);\r\n\t\tgetApiDetails();\r\n\t};\r\n\r\n\tfunction getApiDetails() {\r\n\t\tconst endpointSpan = document.getElementById('api-endpoint');\r\n\t\tapiUrl = endpointSpan ? endpointSpan.textContent : 'http://localhost:3000/query-ai/parking-signs-assistant/';\r\n\t\tconst subKeySpan = document.getElementById('sub-key');\r\n\t\tapiSubKey = subKeySpan ? subKeySpan.textContent : '';\r\n\t}\r\n\r\n\tconst eventHandlers = () => {\r\n\t\tfileSelector.addEventListener('click', e => {\r\n\t\t\te.preventDefault();\r\n\t\t\tfieldGroup.classList.remove('field-group--error');\r\n\t\t\tfileInput.click();\r\n\t\t});\r\n\r\n\t\t// Event listener for the file input to handle file selection\r\n\t\tfileInput.addEventListener('change', () => {\r\n\t\t\tif (fileInput.files.length > 0) {\r\n\t\t\t\tconst fileName = fileInput.files[0].name;\r\n\t\t\t\tuploadedFileName.innerHTML = fileName;\r\n\t\t\t\tuploadedFileNameContainer.classList.remove('display-none');\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\tsubmit.addEventListener('click', async event => {\r\n\t\t\tevent.preventDefault();\r\n\t\t\t// trigger error message\r\n\t\t\tif (fileInput.files.length === 0) {\r\n\t\t\t\tfieldGroup.classList.add('field-group--error');\r\n\t\t\t\treturn;\r\n\t\t\t} else {\r\n\t\t\t\tfieldGroup.classList.remove('field-group--error');\r\n\t\t\t}\r\n\r\n\t\t\t//submit.classList.toggle('btn--loading');\r\n\t\t\ttoggleStep();\r\n\t\t\tuploadMessage();\r\n\t\t});\r\n\r\n\t\tresetFileUpload.addEventListener('click', event => {\r\n\t\t\tevent.preventDefault();\r\n\t\t\tresetDefaults();\r\n\t\t});\r\n\r\n\t\trestartButton.addEventListener('click', event => {\r\n\t\t\tevent.preventDefault();\r\n\t\t\ttoggleStep();\r\n\t\t\tresetDefaults();\r\n\t\t\tscrollToWidget();\r\n\t\t});\r\n\t};\r\n\r\n\tconst scrollToWidget = () => {\r\n\t\tconst offset = 100; // Adjust for 60px above the element\r\n\t\tconst elementPosition = widget.getBoundingClientRect().top + window.scrollY - offset;\r\n\r\n\t\twindow.scrollTo({\r\n\t\t\ttop: elementPosition,\r\n\t\t\tbehavior: 'smooth', // Smooth scrolling animation\r\n\t\t});\r\n\t};\r\n\r\n\tconst toggleStep = () => {\r\n\t\tconst step1 = document.getElementById('parking-signs-widget__step--1');\r\n\t\tconst step2 = document.getElementById('parking-signs-widget__step--2');\r\n\t\tstep1.classList.toggle('display-none');\r\n\t\tstep2.classList.toggle('display-none');\r\n\r\n\t\tbannerStep.innerHTML === '1' ? (bannerStep.innerHTML = 2) : (bannerStep.innerHTML = 1);\r\n\t\tbannerText.innerHTML === bannerTextScreen1\r\n\t\t\t? (bannerText.innerHTML = bannerTextScreen2)\r\n\t\t\t: (bannerText.innerHTML = bannerTextScreen1);\r\n\t\tcalculateBannerProgress(totalBannerSteps);\r\n\t};\r\n\r\n\tconst calculateBannerProgress = totalBannerSteps => {\r\n\t\tconst progress = document.querySelector('.parking-signs-widget__banner__progress-bar__step'),\r\n\t\t\t//CALC WIDTH OF EACH STEP IN THE PROCESS\r\n\t\t\tstepWidth = `${(100 / totalBannerSteps) * parseInt(bannerStep.innerHTML)}%`;\r\n\t\tprogress.style.width = stepWidth;\r\n\t};\r\n\r\n\tconst resetDefaults = () => {\r\n\t\tuploadedFileName.innerHTML = '';\r\n\t\tuploadedFileNameContainer.classList.add('display-none');\r\n\t\tfileInput.value = '';\r\n\t\tresponseDiv.innerHTML = '';\r\n\t\tstatusDiv.innerHTML = '';\r\n\t\tspinner.classList.remove('display-none');\r\n\t\tbannerStep.innerHTML = 1;\r\n\t\tbannerText.innerHTML = bannerTextScreen1;\r\n\t};\r\n\r\n\tconst extractAndFormatMessage = messageData => {\r\n\t\t// Check if the response is valid and has the necessary properties\r\n\t\tif (!messageData.messages) {\r\n\t\t\tconsole.error('Invalid response structure');\r\n\t\t\treturn 'No message content available.';\r\n\t\t}\r\n\r\n\t\t// Extract the first message group\r\n\t\tconst messageGroup = messageData.messages[0];\r\n\r\n\t\t// Extract and format the first valid message\r\n\t\tfor (const message of messageGroup) {\r\n\t\t\tif (message.type === 'text' && message.text && message.text.value) {\r\n\t\t\t\t// Use Marked to convert Markdown to HTML\r\n\t\t\t\treturn `
Error uploading image.
`;\r\n\t\t}\r\n\t};\r\n\r\n\treturn {\r\n\t\tinit: init,\r\n\t};\r\n})();\r\n\r\ndocument.addEventListener('DOMContentLoaded', () => {\r\n\topenAiFile.init();\r\n});\r\n"]}