{"version":3,"sources":["webpack://CoveoForSitecore/./src/ui/analytics/ValidateAnalyticsIncluded.ts"],"names":["element","options","bindings","ValidateAnalyticsIncluded","ID","ComponentOptions","initComponentOptions","bind","onRootElement","SitecoreContextEvents","onSitecoreContextInitialization","sitecoreContextArgs","shouldHaveAnalyticsComponent","this","searchInterfaceHasNoBoundAnalyticsComponent","isInExperienceEditor","errorMessage","component","componentName","checkIfErrorInErrorMessage","console","warn","appendChild","createErrorMessageElement","index","children","length","textContent","indexOf","searchInterface","getComponents","errorSpan","document","createElement","classList","add","buildStringOption","defaultValue","attrName","Component","Initialization","registerAutoCreateComponent"],"mappings":"4qBAAA,WACA,OAMA,0CAUI,WACWA,EACAC,EACAC,GAHX,MAKI,YAAMF,EAASG,EAA0BC,GAAIF,IAAS,K,OAJ/C,EAAAF,UACA,EAAAC,UACA,EAAAC,WAIP,EAAKD,QAAU,EAAAI,iBAAiBC,qBAAqBN,EAASG,EAA2BF,GAEzF,EAAKM,KAAKC,cACN,EAAAC,sBAAsBC,gCACtB,EAAKA,iC,EA2CjB,OAhE+C,OAyBnC,YAAAA,gCAAR,SAAwCC,GACpC,GAAIA,EAAoBC,8BAAgCC,KAAKC,+CACrDH,EAAoBI,qBAAsB,CAC1C,IAAIC,GAsCKC,EAtC0BJ,KAAKZ,QAAQiB,eAAiB,mBAuCtE,uDAAgDD,EAAS,4FArC/CJ,KAAKM,2BAA2BH,KACjCI,QAAQC,KAAKL,GACbH,KAAKb,QAAQsB,YAAYT,KAAKU,0BAA0BP,KAkC5E,IAAyBC,GA5Bb,YAAAE,2BAAR,SAAmCH,GAC/B,IAAK,IAAIQ,EAAQ,EAAGA,EAAQX,KAAKb,QAAQyB,SAASC,OAAQF,IAAS,CAE/D,IAAsD,IADtCX,KAAKb,QAAQyB,SAASD,GAC1BG,YAAYC,QAAQZ,EAAc,GAC1C,OAAO,EAIf,OAAO,GAGH,YAAAF,4CAAR,WACI,OAC+D,IAA3DD,KAAKgB,gBAAgBC,cAAc,aAAaJ,QACsB,IAAtEb,KAAKgB,gBAAgBC,cAAc,wBAAwBJ,QAI3D,YAAAH,0BAAR,SAAkCP,GAC9B,IAAMe,EAAYC,SAASC,cAAc,QAKzC,OAHAF,EAAUG,UAAUC,IAAI,gBACxBJ,EAAUJ,YAAcX,EAEjBe,GA7DJ,EAAA3B,GAAK,4BAEL,EAAAH,QAA6C,CAChDiB,cAAe,EAAAb,iBAAiB+B,kBAAkB,CAC9CC,aAAc,GACdC,SAAU,yBA0DtB,EAhEA,CAA+C,EAAAC,WAsE/C,EAAAC,eAAeC,4BAA4BtC","file":"ValidateAnalyticsIncluded.min.js","sourcesContent":["import { Component, ComponentOptions, IComponentBindings, Initialization } from 'coveo-search-ui';\r\nimport { SitecoreContextEvents, ISitecoreContextInitializationEventArgs } from '../../events/ContextEvents';\r\n\r\nexport interface IValidateAnalyticsIncludedOptions {\r\n componentName: string;\r\n}\r\n\r\nexport class ValidateAnalyticsIncluded extends Component {\r\n static ID = 'ValidateAnalyticsIncluded';\r\n\r\n static options: IValidateAnalyticsIncludedOptions = {\r\n componentName: ComponentOptions.buildStringOption({\r\n defaultValue: '',\r\n attrName: 'data-component-name',\r\n }),\r\n };\r\n\r\n constructor(\r\n public element: HTMLElement,\r\n public options: IValidateAnalyticsIncludedOptions,\r\n public bindings: IComponentBindings\r\n ) {\r\n super(element, ValidateAnalyticsIncluded.ID, bindings);\r\n\r\n this.options = ComponentOptions.initComponentOptions(element, ValidateAnalyticsIncluded, options);\r\n\r\n this.bind.onRootElement(\r\n SitecoreContextEvents.onSitecoreContextInitialization,\r\n this.onSitecoreContextInitialization\r\n );\r\n }\r\n\r\n private onSitecoreContextInitialization(sitecoreContextArgs: ISitecoreContextInitializationEventArgs): void {\r\n if (sitecoreContextArgs.shouldHaveAnalyticsComponent && this.searchInterfaceHasNoBoundAnalyticsComponent()) {\r\n if (sitecoreContextArgs.isInExperienceEditor) {\r\n let errorMessage = getErrorMessage(this.options.componentName || 'Search Interface');\r\n\r\n if (!this.checkIfErrorInErrorMessage(errorMessage)) {\r\n console.warn(errorMessage);\r\n this.element.appendChild(this.createErrorMessageElement(errorMessage));\r\n }\r\n }\r\n }\r\n }\r\n\r\n private checkIfErrorInErrorMessage(errorMessage: string): boolean {\r\n for (let index = 0; index < this.element.children.length; index++) {\r\n const element = this.element.children[index];\r\n if (element.textContent.indexOf(errorMessage, 0) !== -1) {\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n private searchInterfaceHasNoBoundAnalyticsComponent(): boolean {\r\n return (\r\n this.searchInterface.getComponents('Analytics').length === 0 &&\r\n this.searchInterface.getComponents('ForSitecoreAnalytics').length === 0\r\n );\r\n }\r\n\r\n private createErrorMessageElement(errorMessage: string): HTMLElement {\r\n const errorSpan = document.createElement('span');\r\n\r\n errorSpan.classList.add('errorMessage');\r\n errorSpan.textContent = errorMessage;\r\n\r\n return errorSpan;\r\n }\r\n}\r\n\r\nfunction getErrorMessage(component: string): string {\r\n return `The Coveo Analytics are not enabled for this ${component}. Insert a Coveo For Sitecore Analytics component to record Coveo Usage Analytics data.`;\r\n}\r\n\r\nInitialization.registerAutoCreateComponent(ValidateAnalyticsIncluded);\r\n"],"sourceRoot":""}