"use strict";(self.webpackChunkui=self.webpackChunkui||[]).push([[18],{26:(n,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.useProducts=e.gql=void 0;const i=t(3),s=/(query|mutation) ?([\w\d-_]+)? ?\(.*?\)? \{/;e.gql=(n,...e)=>{const t=Array.isArray(n)?[...n,...e].join(""):n,i=s.exec(t);return n=>{const e={query:t};return n&&Object.assign(e,{variables:n}),i&&i.length&&i[2]&&Object.assign(e,{operationName:i[2]}),JSON.stringify(e)}};const r=(0,e.gql)("\n query products($entityIds: [Int!]) {\n site {\n products(entityIds: $entityIds) {\n edges {\n node {\n id\n entityId\n name\n path\n defaultImage {\n ...ImageFields\n }\n reviewSummary {\n summationOfRatings\n numberOfReviews\n }\n prices {\n price {\n ...MoneyFields\n }\n priceRange {\n min {\n ...MoneyFields\n }\n max {\n ...MoneyFields\n }\n }\n salePrice {\n ...MoneyFields\n }\n retailPrice {\n ...MoneyFields\n }\n saved {\n ...MoneyFields\n }\n bulkPricing {\n minimumQuantity\n maximumQuantity\n ... on BulkPricingFixedPriceDiscount {\n price\n }\n ... on BulkPricingPercentageDiscount {\n percentOff\n }\n ... on BulkPricingRelativePriceDiscount {\n priceAdjustment\n }\n }\n }\n brand {\n name\n }\n productOptions(first: 5) {\n edges {\n node {\n entityId\n displayName\n isRequired\n ... on CheckboxOption {\n checkedByDefault\n }\n ... on MultipleChoiceOption {\n values(first: 10) {\n edges {\n node {\n entityId\n label\n isDefault\n ... on SwatchOptionValue {\n hexColors\n imageUrl(width: 200)\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n\n fragment MoneyFields on Money {\n value\n currencyCode\n }\n\n fragment ImageFields on Image {\n size320: url(width: 320)\n size640: url(width: 640)\n size960: url(width: 960)\n size1280: url(width: 1280)\n }\n"),c={},o=n=>{const e=JSON.stringify(n);return c[e]};e.useProducts=n=>{const[{products:e,isProductsFetching:t},s]=(0,i.useState)({products:o(n)||[],isProductsFetching:Boolean(n&&n.length)}),u=(0,i.useRef)(t);u.current=t,(0,i.useEffect)((()=>{n&&n.length&&(o(n)?s((n=>Object.assign(Object.assign({},n),{isProductsFetching:!1}))):(u.current||s((n=>Object.assign(Object.assign({},n),{isProductsFetching:!0}))),fetch("/graphql",{method:"POST",headers:{"Content-Type":"application/json"},body:r({entityIds:n})}).then((n=>n.json())).then((({data:e})=>{const t=(e&&e.site&&e.site.products&&e.site.products.edges||[]).map((n=>{const{node:e}=n;return e}));((n,e)=>{const t=JSON.stringify(n);c[t]=e})(n,t),s({products:t,isProductsFetching:!1})})).catch((n=>{console.error("Products fetch failed",n),s({products:[],isProductsFetching:!1})}))))}),[n]);const d=e&&e.reduce(((n,e)=>(n[null==e?void 0:e.entityId]=e,n)),{});return{products:e,productsById:d,isProductsFetching:t}}}}]);