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;AChNjE,yC","file":"PromotedResultsBadge__d2b01b0f173a0c131e66.js","sourcesContent":["import 'styling/_PromotedResultsBadge';\nimport { $$, ComponentOptions, Dom, Initialization, l, ResultListEvents } from '../../Core';\nimport { IDisplayedNewResultEventArgs } from '../../events/ResultListEvents';\nimport { exportGlobally } from '../../GlobalExports';\nimport { IQueryResult } from '../../rest/QueryResult';\nimport { Component } from '../../ui/Base/Component';\nimport { IComponentBindings } from '../Base/ComponentBindings';\n\nexport interface IPromotedResultsBadgeOptions {\n  showBadgeForFeaturedResults: boolean;\n  showBadgeForRecommendedResults: boolean;\n\n  captionForRecommended: string;\n  captionForFeatured: string;\n\n  colorForFeaturedResults: string;\n  colorForRecommendedResults: string;\n}\n\n/**\n * Depending on its configuration, this component will render badges on query result items whose ranking scores were increased by [featured results](https://docs.coveo.com/en/1961/) query pipeline rules and/or [Coveo ML ART](https://docs.coveo.com/en/1671/#automatic-relevance-tuning-art-feature).\n *\n * This component can be put anywhere in the markup configuration of a search interface. However, it is meant to be initialized only once, and should thus never be included in a result template.\n *\n * @externaldocs [Adding Promoted Results Badges](https://docs.coveo.com/en/3123/)\n * @availablesince [July 2018 Release (v2.4382.10)](https://docs.coveo.com/en/1360/)\n */\nexport class PromotedResultsBadge extends Component {\n  static ID = 'PromotedResultsBadge';\n\n  static doExport = () => {\n    exportGlobally({\n      PromotedResultsBadge\n    });\n  };\n\n  /**\n   * @componentOptions\n   */\n  static options: IPromotedResultsBadgeOptions = {\n    /**\n     * Whether to show a badge when a result was promoted by a featured results query pipeline rule.\n     */\n    showBadgeForFeaturedResults: ComponentOptions.buildBooleanOption({ defaultValue: true }),\n\n    /**\n     * Whether to show a badge when a result was promoted by Coveo ML ART.\n     */\n    showBadgeForRecommendedResults: ComponentOptions.buildBooleanOption({ defaultValue: false }),\n\n    /**\n     * The caption to show on the badge for results promoted by Coveo ML ART.\n     *\n     * Default value is the localized string for `Recommended`.\n     *\n     * @examples Recommended by Coveo ML\n     */\n    captionForRecommended: ComponentOptions.buildLocalizedStringOption({\n      localizedString: () => l('Recommended'),\n      depend: 'showBadgeForRecommendedResults'\n    }),\n\n    /**\n     * The caption to show on the badge for results promoted by a _featured results_ query pipeline rule.\n     *\n     * Default value is the localized string for `Featured`.\n     *\n     * @examples Recommended by ACME\n     */\n    captionForFeatured: ComponentOptions.buildLocalizedStringOption({\n      localizedString: () => l('Featured'),\n      depend: 'showBadgeForFeaturedResults'\n    }),\n\n    /**\n     * The badge color for results promoted by a _featured results_ query pipeline rule.\n     *\n     * Can be specified using:\n     * - a hexadecimal value\n     * - an RGB value\n     * - a CSS color name\n     *\n     * @examples #f58020, rgb(125 10 36), red\n     *\n     * Default value is controlled through the default stylesheet of the framework.\n     */\n    colorForFeaturedResults: ComponentOptions.buildColorOption({ depend: 'showBadgeForFeaturedResults' }),\n\n    /**\n     * The badge color for results promoted by Coveo ML ART.\n     *\n     * Can be specified using:\n     * - a hexadecimal value\n     * - an RGB value\n     * - a CSS color name\n     *\n     * @examples #f58020, rgb(125 10 36), red\n     *\n     * Default value is controlled through the default stylesheet of the framework.\n     */\n    colorForRecommendedResults: ComponentOptions.buildColorOption({ depend: 'showBadgeForRecommendedResults' })\n  };\n\n  constructor(public element: HTMLElement, public options: IPromotedResultsBadgeOptions, public bindings: IComponentBindings) {\n    super(element, PromotedResultsBadge.ID, bindings);\n    this.options = ComponentOptions.initComponentOptions(element, PromotedResultsBadge, options);\n    this.bind.onRootElement(ResultListEvents.newResultDisplayed, (args: IDisplayedNewResultEventArgs) => {\n      const badge = this.buildBadge(args.result, args.item);\n      if (badge) {\n        this.appendBadge(badge, args.item);\n      }\n    });\n  }\n\n  private buildBadge(result: IQueryResult, resultElement: HTMLElement): Dom {\n    if (!this.shouldShowABadge(result, resultElement)) {\n      return null;\n    }\n    const badge = $$('div', {\n      className: this.getClassName(result)\n    });\n\n    this.applyTagline(result, badge);\n    this.applyColor(result, badge);\n    return badge;\n  }\n\n  private appendBadge(badge: Dom, resultElement: HTMLElement) {\n    if (this.isCardLayout(resultElement)) {\n      this.addBadgeToCardLayout(badge, resultElement);\n    } else {\n      $$(resultElement).prepend(badge.el);\n    }\n  }\n\n  private addBadgeToCardLayout(badge: Dom, resultElement: HTMLElement): void {\n    let container: Dom;\n\n    if (resultElement.parentElement == null) {\n      container = $$('div', {\n        className: 'coveo-promoted-result-badge-container-card-layout'\n      });\n\n      container.insertBefore(resultElement);\n    } else {\n      container = $$(resultElement.parentElement);\n    }\n\n    container.append(badge.el);\n    container.append(resultElement);\n  }\n\n  private applyColor(result: IQueryResult, badge: Dom) {\n    if (this.isFeatured(result) && this.options.colorForFeaturedResults) {\n      badge.el.style.backgroundColor = this.options.colorForFeaturedResults;\n    }\n\n    if (this.isRecommended(result) && this.options.colorForRecommendedResults) {\n      badge.el.style.backgroundColor = this.options.colorForRecommendedResults;\n    }\n  }\n\n  private applyTagline(result: IQueryResult, badge: Dom): string {\n    if (this.isFeatured(result) && this.options.showBadgeForFeaturedResults) {\n      badge.text(this.options.captionForFeatured);\n    }\n    if (this.isRecommended(result) && this.options.showBadgeForRecommendedResults) {\n      return badge.text(this.options.captionForRecommended);\n    }\n  }\n\n  private isFeatured(result: IQueryResult): boolean {\n    return result.isTopResult;\n  }\n\n  private isRecommended(result: IQueryResult): boolean {\n    return result.isRecommendation && !result.isTopResult;\n  }\n\n  private isTableLayout(resultElement: HTMLElement): boolean {\n    return $$(resultElement).hasClass('coveo-table-layout');\n  }\n\n  private isCardLayout(resultElement: HTMLElement): boolean {\n    return $$(resultElement).hasClass('coveo-card-layout');\n  }\n\n  private getClassName(result: IQueryResult) {\n    return `coveo-promoted-result-badge coveo-${this.isFeatured(result) ? 'featured' : 'recommended'}-result-badge`;\n  }\n\n  private shouldShowABadge(result: IQueryResult, resultElement: HTMLElement): boolean {\n    if (this.isTableLayout(resultElement)) {\n      return false;\n    }\n\n    if (this.isFeatured(result) && this.options.showBadgeForFeaturedResults) {\n      return true;\n    }\n\n    if (this.isRecommended(result) && this.options.showBadgeForRecommendedResults) {\n      return true;\n    }\n\n    return false;\n  }\n}\n\nInitialization.registerAutoCreateComponent(PromotedResultsBadge);\n\n\n\n// WEBPACK FOOTER //\n// ./src/ui/PromotedResultsBadge/PromotedResultsBadge.ts","// removed by extract-text-webpack-plugin\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./sass/_PromotedResultsBadge.scss\n// module id = 677\n// module chunks = 68 88"],"sourceRoot":""}