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B,QAAQ0B,MAAQ,OAErB,MAAMC,EAAOX,EAASQ,EAClBG,GAAQ,EACVF,EAAKzB,QAAQ0B,MAAQ,QACZC,EAAO,KAChBF,EAAKzB,QAAQ0B,MAAQ,cAGvBF,GACF,CACF,EAGF,SAASrB,IAGP,MAAMyB,EAAwBtB,SAASC,cAAc,YACjDqB,GACFA,EAAsBC,eAAe,CAAEC,SAAU,UAErD,CAQKC,eAAeC,IAAI,iBACtBD,eAAeE,OAAO,eAAgBpD,Y","sources":["webpack://lange/./scripts/sections/rating-stars-element/rating-stars/index.ts","webpack://lange/./scripts/sections/rating-stars-element/rating-stars/index.scss","webpack://lange/./scripts/sections/rating-stars-element/rating-stars/index.html"],"sourcesContent":["import type { CustomElement } from '@integrabeauty/custom-elements';\nimport html from './index.html';\nimport styles from './index.scss';\n\nclass RatingStars extends HTMLElement implements CustomElement {\n  public static get observedAttributes() {\n    return [\n      'data-average',\n      'data-count'\n    ];\n  }\n\n  readonly dataset!: {\n    /**\n     * Boolean flag represented as string to style the review count element accented.\n     */\n    accent: 'false' | 'true';\n\n    /**\n     * Average rating\n     */\n    average: string;\n\n    /**\n     * Total reviews count.\n     */\n    count: string;\n\n    /**\n     * Boolean flag represented as string to disable click. For example, we don't want to scroll\n     * to the reviews section when it's in the paired product card.\n     */\n    disableClick: 'false' | 'true';\n\n    /**\n     * Boolean flag represented as string to display average rating.\n     */\n    displayAverage: 'false' | 'true';\n\n    /**\n     * Boolean flag represented as string to hide reviews count.\n     */\n    hideCount: 'false' | 'true';\n\n    /**\n     * Boolean flag represented as string to mark that the component used for sets.\n     */\n    isSet: 'false' | 'true';\n\n    /**\n     * Boolean flag represented as string to align items to the right.\n     */\n    right: 'false' | 'true';\n\n    /**\n     * Boolean flag represented as string to renders elements stacked rather than in a single line.\n     */\n    stacked: 'false' | 'true';\n  };\n\n  private formatter: Intl.NumberFormat;\n\n  private onDOMContentLoadedBound = this.onDOMContentLoaded.bind(this);\n\n  constructor() {\n    super();\n    this.attachShadow({ mode: 'open' });\n    this.shadowRoot.innerHTML = `<style>${styles}</style>${html}`;\n\n    this.formatter = new Intl.NumberFormat('en-US');\n  }\n\n  public connectedCallback() {\n    this.render();\n    if (this.dataset.disableClick !== 'true') {\n      this.addEventListener('click', onClick);\n    }\n\n    addEventListener('DOMContentLoaded', this.onDOMContentLoadedBound);\n  }\n\n  public disconnectedCallback() {\n    if (this.dataset.disableClick !== 'true') {\n      this.removeEventListener('click', onClick);\n    }\n\n    removeEventListener('DOMContentLoaded', this.onDOMContentLoadedBound);\n  }\n\n  private onDOMContentLoaded() {\n    const productReviewsElement = document.querySelector('#reviews');\n    if (!productReviewsElement) {\n      const wrapper = this.shadowRoot.querySelector('.container');\n      wrapper.classList.add('no-click');\n    }\n  }\n\n  public attributeChangedCallback(_name: string, _oldValue: string, _newValue: string) {\n    this.render();\n  }\n\n  private render() {\n    const count = parseInt(this.dataset.count, 10);\n    const rating = parseFloat(this.dataset.average);\n    if (!count || !rating) {\n      return;\n    }\n\n    this.renderStars();\n\n    const ratingCount = this.shadowRoot.querySelector('.count');\n    ratingCount.textContent = `${this.formatter.format(count)} Reviews`;\n\n    const ratingAverage = this.shadowRoot.querySelector('.average');\n    ratingAverage.textContent = this.dataset.average;\n  }\n\n  private renderStars() {\n    const rating = parseFloat(this.dataset.average);\n    const stars = this.shadowRoot.querySelectorAll<HTMLElement>('.star');\n\n    let i = 0;\n    for (const star of stars) {\n      star.dataset.state = 'full';\n\n      const diff = rating - i;\n      if (diff <= 0) {\n        star.dataset.state = 'empty';\n      } else if (diff < 0.8) {\n        star.dataset.state = 'half-empty';\n      }\n\n      i++;\n    }\n  }\n}\n\nfunction onClick() {\n  // TODO improvement suggestion: for Sets we can go to the review section of the product from\n  // the set\n  const productReviewsElement = document.querySelector('#reviews');\n  if (productReviewsElement) {\n    productReviewsElement.scrollIntoView({ behavior: 'smooth' });\n  }\n}\n\ndeclare global {\n  interface HTMLElementTagNameMap {\n    'rating-stars': RatingStars;\n  }\n}\n\nif (!customElements.get('rating-stars')) {\n  customElements.define('rating-stars', RatingStars);\n}\n","export default \":host([data-disable-click=true]) .container{pointer-events:none}.container{align-items:center;cursor:pointer;display:flex;gap:4px}.container.no-click{cursor:default}.stars{align-items:center;color:#000;display:flex;gap:2px;line-height:1}.star{background-image:url('data:image/svg+xml;utf8,<svg xmlns=\\\"http://www.w3.org/2000/svg\\\" fill=\\\"currentColor\\\" viewBox=\\\"0 0 16 16\\\"><path d=\\\"M3.612 15.443c-.386.198-.824-.149-.746-.592l.83-4.73L.173 6.765c-.329-.314-.158-.888.283-.95l4.898-.696L7.538.792c.197-.39.73-.39.927 0l2.184 4.327 4.898.696c.441.062.612.636.282.95l-3.522 3.356.83 4.73c.078.443-.36.79-.746.592L8 13.187l-4.389 2.256z\\\"/></svg>');background-repeat:no-repeat;height:14px;width:14px}.star[data-state=empty]{background-image:url('data:image/svg+xml;utf8,<svg xmlns=\\\"http://www.w3.org/2000/svg\\\" fill=\\\"currentColor\\\" viewBox=\\\"0 0 16 16\\\"><path d=\\\"M2.866 14.85c-.078.444.36.791.746.593l4.39-2.256 4.389 2.256c.386.198.824-.149.746-.592l-.83-4.73 3.522-3.356c.33-.314.16-.888-.282-.95l-4.898-.696L8.465.792a.513.513 0 0 0-.927 0L5.354 5.12l-4.898.696c-.441.062-.612.636-.283.95l3.523 3.356-.83 4.73zm4.905-2.767-3.686 1.894.694-3.957a.565.565 0 0 0-.163-.505L1.71 6.745l4.052-.576a.525.525 0 0 0 .393-.288L8 2.223l1.847 3.658a.525.525 0 0 0 .393.288l4.052.575-2.906 2.77a.565.565 0 0 0-.163.506l.694 3.957-3.686-1.894a.503.503 0 0 0-.461 0z\\\"/></svg>')}.star[data-state=half-empty]{background-image:url('data:image/svg+xml;utf8,<svg xmlns=\\\"http://www.w3.org/2000/svg\\\" fill=\\\"currentColor\\\" viewBox=\\\"0 0 16 16\\\"><path d=\\\"M5.354 5.119 7.538.792A.516.516 0 0 1 8 .5c.183 0 .366.097.465.292l2.184 4.327 4.898.696A.537.537 0 0 1 16 6.32a.548.548 0 0 1-.17.445l-3.523 3.356.83 4.73c.078.443-.36.79-.746.592L8 13.187l-4.389 2.256a.52.52 0 0 1-.146.05c-.342.06-.668-.254-.6-.642l.83-4.73L.173 6.765a.55.55 0 0 1-.172-.403.58.58 0 0 1 .085-.302.513.513 0 0 1 .37-.245l4.898-.696zM8 12.027a.5.5 0 0 1 .232.056l3.686 1.894-.694-3.957a.565.565 0 0 1 .162-.505l2.907-2.77-4.052-.576a.525.525 0 0 1-.393-.288L8.001 2.223 8 2.226v9.8z\\\" /></svg>')}.count{font-size:.75rem;line-height:1}@media only screen and (min-width:768px){.count{font-size:.75rem}}.average,.count.hide-count{display:none}.average{font-size:.875rem;margin-bottom:-1px;margin-left:4px}:host([data-accent=true]) .count{color:#7c0d3f;font-weight:600;text-decoration:underline}:host([data-small=true]) .star{height:14px;width:14px}:host([data-small=true]) .count{font-size:.75rem}:host([data-stacked=true]) .container{align-items:unset;flex-direction:column}:host([data-right=true]) .container{justify-content:flex-end}:host([data-right=true]):host([data-stacked=true]) .container{align-items:flex-end}:host([data-hide-count=true]) .count{display:none}:host([data-display-average=true]) .average{display:block}:host([data-is-set=true]) .container{margin-top:7px}@media only screen and (min-width:768px){:host([data-is-set=true]) .container{margin-top:4px}}:host([data-is-set=true]) .star{height:8px;width:8px}@media only screen and (min-width:768px){:host([data-is-set=true]) .star{height:12px;width:12px}}\";","// Module\nvar code = \"<div class=\\\"container\\\"><div class=\\\"stars\\\"><span class=\\\"star\\\" data-state=\\\"full\\\"></span><span class=\\\"star\\\" data-state=\\\"full\\\"></span><span class=\\\"star\\\" data-state=\\\"full\\\"></span><span class=\\\"star\\\" data-state=\\\"full\\\"></span><span class=\\\"star\\\" data-state=\\\"full\\\"></span><span class=\\\"average\\\"></span></div><span class=\\\"count\\\"></span></div>\";\n// Exports\nexport default code;"],"names":["RatingStars","HTMLElement","observedAttributes","constructor","super","onDOMContentLoadedBound","this","onDOMContentLoaded","bind","attachShadow","mode","shadowRoot","innerHTML","concat","formatter","Intl","NumberFormat","connectedCallback","render","dataset","disableClick","addEventListener","onClick","disconnectedCallback","removeEventListener","document","querySelector","classList","add","attributeChangedCallback","_name","_oldValue","_newValue","count","parseInt","rating","parseFloat","average","renderStars","textContent","format","stars","querySelectorAll","i","star","state","diff","productReviewsElement","scrollIntoView","behavior","customElements","get","define"],"sourceRoot":""}