"use strict";(self.webpackChunkui=self.webpackChunkui||[]).push([[17],{252:(e,t)=>{function r(e,t){if("string"==typeof t){const r=function(e,t){const r=e.match(/\/(\d+w|\dx\d|original)\//);return null!==r&&r[1]?e.replace(r[1],t):e}(e,null!=t?t:"200w");return r}return e}Object.defineProperty(t,"__esModule",{value:!0}),t.prepareFastImageUrl=void 0,t.prepareFastImageUrl=function(e,t){const o=e.replace("https://cdn11.bigcommerce.com/s-r4tr0","/fast-image/de");return o.includes("stencil")?r(o,t):function(e,t){const[o]=e.split("?");if(!o)return e;const a=function(e){const t=e.match(/(\d+[.]\d+\.(jpg|png|gif))/i);return null!==t&&t[1]?e.replace(t[1],"jpg"):e}(o);return r(a.replace("/images","").replace("/products","/images/stencil/200w/products"),t)}(o,t)}},253:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.comingSoonImage=void 0,t.comingSoonImage={url:"https://cdn11.bigcommerce.com/s-r4tr0/product_images/uploaded_images/image-coming-soon.jpg",altText:"Image not found"}},10:function(e,t,r){var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.PriceComponent=void 0;const a=r(0),n=(r(1),r(2)),i=o(r(29)),{wrapper:s,wrapperArtificialPrice:u,wrapperSavingsLabel:c,wrapperRetailPrice:l}=i.default;t.PriceComponent=({priceData:{price:e,displayPrice:t,retailPrice:r},savingsLabel:o,isArtificialPriceAvailable:i})=>{const d="number"==typeof r&&r>0,g=(0,n.transformLabelByMultipleOptions)(o,{price:e,displayPrice:t,retailPrice:r}),p=i&&g&&g.length>0;return(0,a.jsxs)("div",Object.assign({className:s},{children:[d&&(0,a.jsx)("span",Object.assign({className:l},{children:(0,n.formatCurrency)(r)})),(0,a.jsx)("span",Object.assign({className:(0,n.cx)(s,p?u:"")},{children:(0,n.formatCurrency)(t)})),p&&(0,a.jsx)("div",{className:c,dangerouslySetInnerHTML:{__html:g}})]}))}},33:function(e,t,r){var o=this&&this.__awaiter||function(e,t,r,o){return new(r||(r=Promise))((function(a,n){function i(e){try{u(o.next(e))}catch(e){n(e)}}function s(e){try{u(o.throw(e))}catch(e){n(e)}}function u(e){var t;e.done?a(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,s)}u((o=o.apply(e,t||[])).next())}))},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.useStateFromURL=t.useCollectionSEO=t.useSortingState=t.usePagination=t.useCategoryModal=t.useCollection=void 0;const n=r(3),i=r(2),s=r(32),u=r(14),c=a(r(5));t.useCollection=({category:e,artificialPriceService:r,customerId:o,isLoggedIn:a})=>{const[i,u]=(0,n.useState)(!0),[c,l]=(0,n.useState)((0,s.getInitialSortValue)(e)),[d,g]=(0,n.useState)((0,s.getInitialCurrentProductList)(e)),[p,f]=(0,n.useState)(null),[P,v]=(0,n.useState)((0,s.getInitialProductsLoadingStatus)(e)),[y,m]=(0,n.useState)(!1),{modalData:h,modalSetPriceData:C,closeModal:S}=(0,t.useCategoryModal)(),{page:I,currentPage:_,setPage:w,setCurrentPage:L,handlePagination:b}=(0,t.usePagination)({sortBy:c,category:e,currentProductList:d,artificialPriceService:r,setCurrentProductList:g,setProductsLoadingStatus:v,setIsInitial:u}),{handleSort:x}=(0,t.useSortingState)({categoryData:e,urlParamsFetched:y,fullProductCategory:p,isInitial:i,sortBy:c,artificialPriceService:r,setSortBy:l,setPage:w,setFullProductCategory:f,setProductsLoadingStatus:v,setCurrentPage:L,setCurrentProductList:g,setIsInitial:u});return(0,t.useStateFromURL)({setPage:w,setSortBy:l,setURLParamsFetched:m}),(0,t.useCollectionSEO)({categoryData:e,page:I,sortBy:c,currentPage:_,currentListedProducts:d,isLoggedIn:a,customerId:o}),{currentProductList:d,productsLoadingStatus:P,page:I,sortBy:c,currentPage:_,modalData:h,setPage:w,handlePagination:b,modalSetPriceData:C,handleSort:x,closeModal:S}},t.useCategoryModal=()=>{const[e,t]=(0,n.useState)({modalIsOpen:!1,product:{id:0,name:"",price:0,image:{altText:"",url:""},retailPrice:0,displayPrice:0,displayRetailPrice:0}});return{modalData:e,modalSetPriceData:t,closeModal:()=>t(Object.assign(Object.assign({},e),{modalIsOpen:!1}))}},t.usePagination=({category:e,sortBy:t,currentProductList:r,artificialPriceService:a,setCurrentProductList:i,setProductsLoadingStatus:u,setIsInitial:c})=>{const[l,d]=(0,n.useState)(1),[g,p]=(0,n.useState)(0);return{page:l,setPage:d,currentProductList:r,setCurrentProductList:i,currentPage:g,setCurrentPage:p,handlePagination:function(n){var l,d;return o(this,void 0,void 0,(function*(){switch(c(!1),n){case"PREVIOUS":p((e=>e-1));break;case"NEXT":{u("Loading");const o=g+1;if(null!==r&&!r[o]){const o=null!==(d=null===(l=r[g])||void 0===l?void 0:l.endCursor)&&void 0!==d?d:null,n=yield(0,s.fetchNextPaginatedCategoryProducts)(t,e,o);if(!n)return;const u=(0,s.prepareCollectionProducts)(n.products,a);i((e=>{var t,r;const o={products:u,endCursor:(null===(t=n.pageInfo)||void 0===t?void 0:t.endCursor)||"",hasNextPage:(null===(r=n.pageInfo)||void 0===r?void 0:r.hasNextPage)||!1};return e?[...e,o]:[o]}))}p(o);break}default:console.error("Unsupported pagination method")}u("Loaded")}))}}},t.useSortingState=({categoryData:e,urlParamsFetched:t,fullProductCategory:r,isInitial:a,sortBy:i,artificialPriceService:u,setSortBy:l,setCurrentProductList:d,setFullProductCategory:g,setProductsLoadingStatus:p,setCurrentPage:f,setIsInitial:P})=>((0,n.useEffect)((()=>{e&&"new arrivals"===e.name.toLowerCase()&&l("NEWEST")}),[e]),(0,n.useEffect)((()=>{const{isFirstPageFromCache:n,isSortValueContextCorrect:l}=(0,s.getCollectionValidationResults)(e);n&&l&&a||o(void 0,void 0,void 0,(function*(){try{if(!t)return null;let o;if(p("Loading"),"QUANTITY_ASC"===i||"QUANTITY_DESC"===i){if(r)o=[...r];else{const t=yield(0,s.fetchFullProductCategory)(i,e);g(t),o=[...t]}const t=(0,s.sortProductsByQuantity)(o,i),a=(0,s.prepareCollectionProducts)(t,u),n=(0,s.paginateAllCategoryProducts)(a);d(n)}else{const t=yield(0,s.fetchNextPaginatedCategoryProducts)(i,e);if(t){const e=(0,s.prepareCollectionProducts)(null==t?void 0:t.products,u)||[];e.length>0&&d((r=>{var o,a;const n={products:e,endCursor:(null===(o=null==t?void 0:t.pageInfo)||void 0===o?void 0:o.endCursor)||"",hasNextPage:(null===(a=null==t?void 0:t.pageInfo)||void 0===a?void 0:a.hasNextPage)||!1};return r?[...r,n]:[n]}))}}}catch(e){return c.default.fire({icon:"error",text:"We're sorry, we couldn't find more products."})}finally{p("Loaded")}}))}),[t]),{sortBy:i,setSortBy:l,handleSort:a=>o(void 0,void 0,void 0,(function*(){try{const o=a.currentTarget.value;l(o),P(!1),f(0),p("Loading");const n=new URL(window.location.pathname,window.location.origin);n.searchParams.set("sort",o);const{isFirstPageFromCache:i,doesNewSortValueEqualToDefaultOne:c}=(0,s.getCollectionValidationResults)(e,o);if(i&&c)return d([{products:e.products,endCursor:e.endCursor,hasNextPage:e.hasNextPage}]),p("Loaded"),void window.history.pushState({},"",n.toString());if(!t)return null;let v;if("QUANTITY_ASC"===o||"QUANTITY_DESC"===o){if(r)v=[...r];else{const t=yield(0,s.fetchFullProductCategory)(o,e);g(t),v=[...t]}const t=(0,s.sortProductsByQuantity)(v,o),a=(0,s.prepareCollectionProducts)(t,u),n=(0,s.paginateAllCategoryProducts)(a);d(n)}else{const t=yield(0,s.fetchNextPaginatedCategoryProducts)(o,e);if(t){const e=(0,s.prepareCollectionProducts)(null==t?void 0:t.products,u)||[];e.length>0&&d((r=>{var o,a;return[{products:e,endCursor:(null===(o=null==t?void 0:t.pageInfo)||void 0===o?void 0:o.endCursor)||"",hasNextPage:(null===(a=null==t?void 0:t.pageInfo)||void 0===a?void 0:a.hasNextPage)||!1}]}))}}return p("Loaded"),void window.history.pushState({},"",n.toString())}catch(e){return c.default.fire({icon:"error",text:"We're sorry, we are not able to sort that way right now."})}}))}),t.useCollectionSEO=({categoryData:e,page:t,sortBy:r,currentListedProducts:o,currentPage:a,isLoggedIn:i,customerId:c})=>{const[l,d]=(0,n.useState)(!0),{push:g,setServer:p}=(0,u.useDataLayer)(i,c);(0,n.useEffect)((()=>{p(),g({ecomm_pagetype:"category",category:e.name});const t=(0,s.getCurrentProductList)(o,a).map((e=>String(e.id)));g({ecomm_prodid:t})}),[]),(0,n.useEffect)((()=>{if("undefined"!=typeof window){if(window.dataLayer){const t=(0,s.getCurrentProductList)(o,a),r=t.map((e=>String(e.id))),n=t.map((e=>({id:String(e.id),google_business_vertical:"retail"})));g({ecomm_prodid:r}),l||g({event:"routeChange"});const i=null==n?void 0:n.map((({id:e})=>e)).slice(0,4).join(",");g({event:"view_item_list",value:null==o?void 0:o.reduce(((e,{price:t})=>e+t),0),items:n,facebook:{content_name:null==e?void 0:e.name,content_ids:i,content_type:"product_group"},bing:{ecomm_category:[null==e?void 0:e.id],ecomm_prodid:i,ecomm_pagetype:"category",ecomm_page:"category"}}),d&&d(!1)}}else console.warn("[SSR] - Undefined Window Object - Analytics Tracking Unavailable")}),[t,r])},t.useStateFromURL=({setPage:e,setSortBy:t,setURLParamsFetched:r})=>{const o=()=>{const{pageParam:o,sortParam:a}=(0,i.getParamsFromURL)();o&&e(o),a&&t(a),r(!0)};(0,n.useEffect)(o,[]),(0,n.useEffect)((()=>(window.addEventListener("popstate",o),()=>{window.removeEventListener("popstate",o)})),[])}},32:function(e,t,r){var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var a=Object.getOwnPropertyDescriptor(t,r);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,a)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),a=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),n=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return a(t,e),t},i=this&&this.__awaiter||function(e,t,r,o){return new(r||(r=Promise))((function(a,n){function i(e){try{u(o.next(e))}catch(e){n(e)}}function s(e){try{u(o.throw(e))}catch(e){n(e)}}function u(e){var t;e.done?a(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,s)}u((o=o.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getCurrentProductList=t.getInitialProductsLoadingStatus=t.paginateAllCategoryProducts=t.sortProductsByQuantity=t.getCollectionValidationResults=t.getInitialCurrentProductList=t.getInitialSortValue=t.prepareCollectionProducts=t.getCategoryInfo=t.fetchFullProductCategory=t.fetchNextPaginatedCategoryProducts=void 0;const u=s(r(5)),c=n(r(16)),l=r(2),d=r(252),g=r(253),p=r(19),f=r(12);function P(e,t,r,o,a){var n;return i(this,void 0,void 0,(function*(){try{const i=c.gql` query paginateCategoryProducts( $pageSize: Int $afterCursor: String $categoryId: Int! ) { site { category(entityId: $categoryId) { name defaultProductSort products( first: $pageSize after: $afterCursor hideOutOfStock: true sortBy: ${o||e} ) { pageInfo { hasNextPage hasPreviousPage startCursor endCursor } edges { node { name id: entityId path availabilityV2{ status } productOptions { edges { node { entityId } } } variants { edges { node { id: entityId inventory { aggregated { availableToSell } } } } } prices { price { value } retailPrice { value } } defaultImage { url(width: 400) altText } } } } } } } `,s=yield(0,c.default)("/graphql",i,{categoryId:t.id,pageSize:a||16,afterCursor:r}),u=null===(n=null==s?void 0:s.site)||void 0===n?void 0:n.category.products;return{products:u.edges.map((e=>e.node)).slice(0,a||16),pageInfo:u.pageInfo}}catch(e){return console.error(e),void u.default.fire({icon:"error",text:"Sorry, there was a problem fetching products, please refresh your page and try again."})}}))}function v(e,t){return!(void 0===e||!t.includes(e.name.toLowerCase())&&(!e.parent||!t.includes(e.parent.name.toLowerCase())))}function y(e,t){const r=e.products.length>0,o=e.sortByParam===e.defaultProductSort,a=e.defaultProductSort&&0===e.sortByParam.length;return{isFirstPageFromCache:r,doesSortValueParamEqualToDefaultOne:o,isOnlyDefaultSortValue:a,isSortValueContextCorrect:o||a,doesNewSortValueEqualToDefaultOne:e.defaultProductSort===t}}t.fetchNextPaginatedCategoryProducts=P,t.fetchFullProductCategory=function(e,t){var r;return i(this,void 0,void 0,(function*(){let o=[],a=null;do{try{const n=yield P(e,t,a,"DEFAULT",50);if(!n)throw new Error;o=[...o,...n.products],a=null===(r=null==n?void 0:n.pageInfo)||void 0===r?void 0:r.endCursor}catch(e){console.error(e),u.default.fire({icon:"error",text:"Sorry, there was a problem fetching products, please refresh your page and try again."})}}while(a);return o}))},t.getCategoryInfo=(e,t,r)=>{const o={__html:(e?e.description:t.description).replaceAll("https://discountelectronics.com/","/")};let a=!1,n=!1;const i=r&&r.name&&r.name.toLowerCase();return"used computers"===i||"used laptops"===i?a=!0:"used monitors"===i||"used monitors"===i?n=!0:r.parent&&(a=v(r.parent,["used computers","used laptops"]),n=v(r.parent,["used monitors","used monitors"])),{categoryDescription:o,showCategoryIcons:a,showMonitorIcons:n}},t.prepareCollectionProducts=(e,t)=>{if(!e)return[];const r=e.map((e=>{var t,r,o,a,n,i,s,u;const c="preorder"===e.availabilityV2.status.toLowerCase(),[l]=e.variants.edges,p=(null===(t=null==l?void 0:l.node)||void 0===t?void 0:t.id)||0,f=void 0!==e.defaultImage&&null!==(null==e?void 0:e.defaultImage)?e.defaultImage:g.comingSoonImage,P=e.prices.price.value,v=null!==(o=null===(r=e.prices.retailPrice)||void 0===r?void 0:r.value)&&void 0!==o?o:null;return{id:e.id,baseVariantId:p,image:{url:(0,d.prepareFastImageUrl)(f.url,"400w"),altText:e.name},hasOptions:e.productOptions.edges.length>0,inventoryLevel:(null===(u=null===(s=null===(i=null===(n=null===(a=e.variants)||void 0===a?void 0:a.edges[0])||void 0===n?void 0:n.node)||void 0===i?void 0:i.inventory)||void 0===s?void 0:s.aggregated)||void 0===u?void 0:u.availableToSell)||0,inventoryTracking:"product",isPreorderOnly:c,name:e.name,price:P,displayPrice:P,retailPrice:v,displayRetailPrice:v,url:e.path}})),o="undefined"!=typeof document?(0,f.getCookieItem)("artificial_expiration_time"):void 0;return(0,p.prepareSubProductsWithArtificialPriceService)(r,t,{artificialExpirationTimeCookieValue:o})},t.getInitialSortValue=function(e){return e.sortByParam?e.sortByParam:e.defaultProductSort},t.getInitialCurrentProductList=function(e){const{isFirstPageFromCache:t,isSortValueContextCorrect:r}=y(e);return t&&r?[{products:e.products,endCursor:e.endCursor,hasNextPage:e.hasNextPage}]:null},t.getCollectionValidationResults=y,t.sortProductsByQuantity=function(e,t){return e.sort(((e,r)=>{const o=(0,l.combineVariantInventory)(e.variants.edges),a=(0,l.combineVariantInventory)(r.variants.edges);return"QUANTITY_ASC"===t?o>a?1:oa?-1:0}))},t.paginateAllCategoryProducts=function(e){return e.reduce(((e,t,r)=>{const o=Math.floor(r/16);r%16==0&&e.push({products:[],endCursor:"",hasNextPage:!1});const a=e[o];return void 0!==a&&a.products.push(t),e}),[])},t.getInitialProductsLoadingStatus=function(e){const{isFirstPageFromCache:t,isSortValueContextCorrect:r}=y(e);return t&&r?"Loaded":"Loading"},t.getCurrentProductList=function(e,t){var r;if(null===e)return[];const o=e[t];return void 0!==o&&null!==(r=o.products)&&void 0!==r?r:[]}}}]);