{"version":3,"file":"personalization_controller-C-gWweZ_.js","sources":["../../../app/javascript/controllers/webchat/personalization_controller.js"],"sourcesContent":["import ApplicationController from '@/controllers/application_controller'\n\nexport default class extends ApplicationController {\n static values = {\n object: Object,\n }\n\n static targets = [\n 'primaryColorPicker',\n 'secondaryColorPicker',\n 'input',\n 'preview',\n 'logo',\n ]\n\n connect() {\n this.changeForegroundColor()\n this.changeBackgroundColor()\n\n super.connect()\n }\n\n onColorChange(event) {\n const target = event.srcElement.closest('[data-webchat--personalization-target]')\n\n if(target === this.primaryColorPickerTarget) {\n this.objectValue = {\n ...this.objectValue,\n primary_color: event.detail.rgba,\n }\n\n this.changeForegroundColor()\n } else {\n this.objectValue = {\n ...this.objectValue,\n secondary_color: event.detail.rgba,\n }\n\n this.changeBackgroundColor()\n }\n }\n\n changeForegroundColor() {\n this.previewTarget.style.setProperty('--webchat-primary-color', this.objectValue.primary_color)\n\n let rgba = this.objectValue.primary_color\n this.previewTarget.style.setProperty('--webchat-message-background-color', this.changeAlpha(rgba, 0.3))\n }\n\n changeBackgroundColor() {\n this.previewTarget.style.setProperty('--webchat-secondary-color', this.objectValue.secondary_color)\n }\n\n mimicMessageSending(e) {\n this.inputTarget.value = \"\"\n }\n\n onTypographyChange({ currentTarget }) {\n const { optionValue: fontFamily } = currentTarget.dataset\n this.previewTarget.style.fontFamily = fontFamily\n }\n\n changeAlpha(rgba, newAlpha) {\n return rgba.replace(/rgba?\\((\\d+), (\\d+), (\\d+),? (\\d*\\.?\\d+)?\\)/, (match, r, g, b) => {\n return `rgba(${r}, ${g}, ${b}, ${newAlpha})`;\n });\n }\n}\n"],"names":["personalization_controller","ApplicationController","event","rgba","currentTarget","fontFamily","newAlpha","match","r","g","b","__publicField"],"mappings":"uNAEe,MAAKA,UAASC,CAAsB,CAajD,SAAU,CACR,KAAK,sBAAqB,EAC1B,KAAK,sBAAqB,EAE1B,MAAM,QAAO,CACjB,CAEE,cAAcC,EAAO,CACJA,EAAM,WAAW,QAAQ,wCAAwC,IAElE,KAAK,0BACjB,KAAK,YAAc,CACjB,GAAG,KAAK,YACR,cAAeA,EAAM,OAAO,IACpC,EAEM,KAAK,sBAAqB,IAE1B,KAAK,YAAc,CACjB,GAAG,KAAK,YACR,gBAAiBA,EAAM,OAAO,IACtC,EAEM,KAAK,sBAAqB,EAEhC,CAEE,uBAAwB,CACtB,KAAK,cAAc,MAAM,YAAY,0BAA2B,KAAK,YAAY,aAAa,EAE9F,IAAIC,EAAO,KAAK,YAAY,cAC5B,KAAK,cAAc,MAAM,YAAY,qCAAsC,KAAK,YAAYA,EAAM,EAAG,CAAC,CAC1G,CAEE,uBAAwB,CACtB,KAAK,cAAc,MAAM,YAAY,4BAA6B,KAAK,YAAY,eAAe,CACtG,CAEE,oBAAoB,EAAG,CACrB,KAAK,YAAY,MAAQ,EAC7B,CAEE,mBAAmB,CAAE,cAAAC,GAAiB,CACpC,KAAM,CAAE,YAAaC,CAAY,EAAGD,EAAc,QAClD,KAAK,cAAc,MAAM,WAAaC,CAC1C,CAEE,YAAYF,EAAMG,EAAU,CAC1B,OAAOH,EAAK,QAAQ,8CAA+C,CAACI,EAAOC,EAAGC,EAAGC,IACxE,QAAQF,CAAC,KAAKC,CAAC,KAAKC,CAAC,KAAKJ,CAAQ,GAC1C,CACL,CACA,CAhEEK,EADkBX,EACX,SAAS,CACd,OAAQ,MACZ,GAEEW,EALkBX,EAKX,UAAU,CACf,qBACA,uBACA,QACA,UACA,MACJ"}