{"version":3,"sources":["src/components/search/atomic-did-you-mean/atomic-did-you-mean.pcss?tag=atomic-did-you-mean&encapsulation=shadow","src/components/search/atomic-did-you-mean/atomic-did-you-mean.tsx"],"names":["atomicDidYouMeanCss","AtomicDidYouMean","[object Object]","this","didYouMean","buildDidYouMean","bindings","engine","queryTrigger","buildQueryTrigger","key","query","h","LocalizedString","params","part","Fragment","class","withQuery","queryTriggerState","newQuery","onClick","undo","_a","originalQuery","didYouMeanState","wasCorrectedTo","applyCorrection","queryCorrection","correctedQuery","hasQueryCorrection","wasAutomaticallyCorrected","renderDidYouMeanAutomaticallyCorrected","renderDidYouMeanCorrection","_b","wasQueryModified","renderQueryTriggerAutomaticallyCorrected","Hidden","__decorate","InitializeBindings","BindStateToController"],"mappings":"sPAAA,MAAMA,EAAsB,w79BCmCfC,EAAgB,+BAapBC,aACLC,KAAKC,WAAaC,EAAgBF,KAAKG,SAASC,QAChDJ,KAAKK,aAAeC,EAAkBN,KAAKG,SAASC,QAG9CL,UACNQ,EAIAC,GAEA,OACEC,EAACC,EAAe,CACdP,SAAUH,KAAKG,SACfI,IAAKA,EACLI,OAAQ,CAACH,MAAOC,EAAA,IAAA,CAAGG,KAAK,aAAaJ,MAKnCT,iDACN,OACEU,EAACI,EAAQ,KACPJ,EAAA,IAAA,CACEK,MAAM,uCACNF,KAAK,uBAEJZ,KAAKe,UACJ,sBACAf,KAAKgB,kBAAmBC,WAG5BR,EAAA,IAAA,CACEK,MAAM,yCACNF,KAAK,sBAELH,EAACC,EAAe,CACdP,SAAUH,KAAKG,SACfI,IAAI,qBACJI,OAAQ,CACNH,MACEC,EAAA,SAAA,CACEK,MAAM,YACNF,KAAK,WACLM,QAAS,IAAMlB,KAAKK,aAAac,SAEhCC,EAAApB,KAAKgB,qBAAiB,MAAAI,SAAA,OAAA,EAAAA,EAAEC,oBAUjCtB,yCACN,OACEU,EAACI,EAAQ,KACPJ,EAAA,IAAA,CAAGK,MAAM,0BAA0BF,KAAK,cACrCZ,KAAKe,UACJ,8BACAf,KAAKsB,gBAAiBD,gBAG1BZ,EAAA,IAAA,CAAGK,MAAM,qBAAqBF,KAAK,kBAChCZ,KAAKe,UACJ,0BACAf,KAAKsB,gBAAiBC,kBAOxBxB,6BACN,OACEU,EAAA,IAAA,CAAGK,MAAM,qBAAqBF,KAAK,gBACjCH,EAACC,EAAe,CACdP,SAAUH,KAAKG,SACfI,IAAI,eACJI,OAAQ,CACNH,MACEC,EAAA,SAAA,CACEK,MAAM,YACNF,KAAK,iBACLM,QAAS,IAAMlB,KAAKC,WAAWuB,mBAE9BxB,KAAKsB,gBAAiBG,gBAAgBC,oBAS9C3B,iBACL,IAAIqB,EAAApB,KAAKsB,mBAAe,MAAAF,SAAA,OAAA,EAAAA,EAAEO,mBAAoB,CAC5C,GAAI3B,KAAKsB,gBAAgBM,0BAA2B,CAClD,OAAO5B,KAAK6B,yCAEd,OAAO7B,KAAK8B,6BAGd,IAAIC,EAAA/B,KAAKgB,qBAAiB,MAAAe,SAAA,OAAA,EAAAA,EAAEC,iBAAkB,CAC5C,OAAOhC,KAAKiC,2CAGd,OAAOxB,EAACyB,EAAM,QA1HMC,EAAA,CAArBC,uCAIAC,EAAsB,wDAGtBA,EAAsB","sourcesContent":["@import '../../../global/global.pcss';\n","import {\n DidYouMean,\n DidYouMeanState,\n buildDidYouMean,\n QueryTrigger,\n buildQueryTrigger,\n QueryTriggerState,\n} from '@coveo/headless';\nimport {Component, Fragment, h, State} from '@stencil/core';\nimport {\n BindStateToController,\n InitializableComponent,\n InitializeBindings,\n} from '../../../utils/initialization-utils';\nimport {LocalizedString} from '../../../utils/jsx-utils';\nimport {Hidden} from '../../common/hidden';\nimport {Bindings} from '../atomic-search-interface/atomic-search-interface';\n\n/**\n * The `atomic-did-you-mean` component is responsible for handling query corrections. When a query returns no result but finds a possible query correction, the component either suggests the correction or automatically triggers a new query with the suggested term.\n *\n * @part no-results - The text displayed when there are no results.\n * @part auto-corrected - The text displayed for the automatically corrected query.\n * @part showing-results-for - The first paragraph of the text displayed when a query trigger changes a query.\n * @part search-instead-for - The second paragraph of the text displayed when a query trigger changes a query.\n * @part did-you-mean - The text displayed around the button to manually correct a query.\n * @part correction-btn - The button used to manually correct a query.\n * @part undo-btn - The button used to undo a query changed by a query trigger.\n * @part highlight - The query highlights.\n */\n@Component({\n tag: 'atomic-did-you-mean',\n styleUrl: 'atomic-did-you-mean.pcss',\n shadow: true,\n})\nexport class AtomicDidYouMean implements InitializableComponent {\n @InitializeBindings() public bindings!: Bindings;\n private didYouMean!: DidYouMean;\n protected queryTrigger!: QueryTrigger;\n\n @BindStateToController('didYouMean')\n @State()\n private didYouMeanState?: DidYouMeanState;\n @BindStateToController('queryTrigger')\n @State()\n private queryTriggerState?: QueryTriggerState;\n @State() public error!: Error;\n\n public initialize() {\n this.didYouMean = buildDidYouMean(this.bindings.engine);\n this.queryTrigger = buildQueryTrigger(this.bindings.engine);\n }\n\n private withQuery(\n key:\n | 'no-results-for-did-you-mean'\n | 'query-auto-corrected-to'\n | 'showing-results-for',\n query: string\n ) {\n return (\n {query}}}\n />\n );\n }\n\n private renderQueryTriggerAutomaticallyCorrected() {\n return (\n \n \n {this.withQuery(\n 'showing-results-for',\n this.queryTriggerState!.newQuery\n )}\n

\n \n this.queryTrigger.undo()}\n >\n {this.queryTriggerState?.originalQuery}\n \n ),\n }}\n />\n

\n
\n );\n }\n\n private renderDidYouMeanAutomaticallyCorrected() {\n return (\n \n

\n {this.withQuery(\n 'no-results-for-did-you-mean',\n this.didYouMeanState!.originalQuery\n )}\n

\n

\n {this.withQuery(\n 'query-auto-corrected-to',\n this.didYouMeanState!.wasCorrectedTo\n )}\n

\n
\n );\n }\n\n private renderDidYouMeanCorrection() {\n return (\n

\n this.didYouMean.applyCorrection()}\n >\n {this.didYouMeanState!.queryCorrection.correctedQuery}\n \n ),\n }}\n />\n

\n );\n }\n\n public render() {\n if (this.didYouMeanState?.hasQueryCorrection) {\n if (this.didYouMeanState.wasAutomaticallyCorrected) {\n return this.renderDidYouMeanAutomaticallyCorrected();\n }\n return this.renderDidYouMeanCorrection();\n }\n\n if (this.queryTriggerState?.wasQueryModified) {\n return this.renderQueryTriggerAutomaticallyCorrected();\n }\n\n return ;\n }\n}\n"]}