{"version":3,"file":"productFilter-c4004dd0.js","sources":["../../../src/js/modules/productFilter.js"],"sourcesContent":["// Implements live filtering\n// Implements ARIA Live Region to announce that content on the page has updated as a result of user action\n// https://www.scottohara.me/blog/2022/02/05/are-we-live.html\n\nlet filterType = document.querySelector(\"#filterType\");\nlet productsWrapper = document.querySelector('.productsWrapper');\nconst productTypes = document.querySelectorAll(\".productsWrapper > .cardSmall\");\n\n\nconst doFiltering = () => {\n\t/* Early exit if function not needed */\n\tif (!productsWrapper) {\n\t\tconsole.info('There is no .productsWrapper, exiting function');\n\t\treturn;\n\t}\n\n\t// console.log(\"---new run---\");\n\t/*\n\t\tExplanation:\n\t\t- We build a `searchArray` which contains the parameters that the user is searching against, this is taken from the form inputs\n\t\t- We loop through each property type, and test its parameter values against the search parameters, to build a `matchArray`\n\t\t- We stringify both arrays so that we can then compare and see if they are identical - if so, the productType was a match for the search criteria\n\t*/\n\n\tproductTypes.forEach(productTypeSingle => {\n\t\t// hide all on first run, visually and in the a11y tree\n\t\t// productTypeSingle.classList.add('uc_hide-for-everyone');\n\t\tproductTypeSingle.setAttribute(\"aria-hidden\", \"true\");\n\t\t// console.log( productTypeSingle );\n\n\t\tconst searchArray = []; // what is the user looking for\n\t\tconst matchArray = []; // what matches on this plot\n\n\t\t// build the search array and Aria message. This only adds what PROPERTY needs to be matched, and not the VALUE. Tests are done independently of this array.\n\t\tif( filterType ) {\n\t\t\tif( filterType.value != \"any\" ) { searchArray.push('product-type'); }\n\t\t}\n\n\t\t// build the match array\n\t\tif( filterType ) {\n\t\t\tif( filterType.value == productTypeSingle.dataset.productType ) {\n\t\t\t\tmatchArray.push('product-type');\n\t\t\t}\n\t\t}\n\n\t\t// if the searchArray is the same as the matchArray then the cottage was a complete match on all the searched items and should be shown\n\t\tif( JSON.stringify(searchArray) == JSON.stringify(matchArray) ) {\n\t\t\tproductTypeSingle.classList.remove('uc_hide-for-everyone');\n\t\t\tproductTypeSingle.setAttribute(\"aria-hidden\", \"false\");\n\t\t} else {\n\t\t\tproductTypeSingle.classList.add('uc_hide-for-everyone');\n\t\t\tproductTypeSingle.setAttribute(\"aria-hidden\", \"true\");\n\t\t}\n\n\t\tconsole.log( \"searchArray\", JSON.stringify(searchArray) );\n\t\tconsole.log( \"matchArray\", JSON.stringify(matchArray) );\n\t});\n\n\tlet numberMatchedproductTypes = document.querySelectorAll('.productsWrapper > .cardSmall:not(.uc_hide-for-everyone)').length;\n\n\tif (filterType) {\n\t\tif (filterType.value != \"any\") {\n\t\t}\n\t\telse {\n\t\t}\n\n\t\tconsole.log( filterType.value );\n\t}\n\n\t// handle if no matches so it's a bit more friendly\n\tdocument.querySelector(\"#noMatches\")?.remove();\n\tif( numberMatchedproductTypes == 0 ) {\n\t\tproductsWrapper.insertAdjacentHTML('afterBegin', `

Sorry, there are no products of that type right now.

`);\n\t}\n};\n\n// watch for changes\n\tif( filterType ) {\n\t\tfilterType.addEventListener('change', doFiltering);\n\t}\n\ndoFiltering();\n"],"names":["filterType","productsWrapper","productTypes","doFiltering","_a","productTypeSingle","searchArray","matchArray","numberMatchedproductTypes"],"mappings":"AAIA,IAAIA,EAAa,SAAS,cAAc,aAAa,EACjDC,EAAkB,SAAS,cAAc,kBAAkB,EAC/D,MAAMC,EAAe,SAAS,iBAAiB,+BAA+B,EAGxEC,EAAc,IAAM,CAT1B,IAAAC,EAWC,GAAI,CAACH,EAAiB,CACrB,QAAQ,KAAK,gDAAgD,EAC7D,MACA,CAUDC,EAAa,QAAQG,GAAqB,CAGzCA,EAAkB,aAAa,cAAe,MAAM,EAGpD,MAAMC,EAAc,CAAA,EACdC,EAAc,CAAA,EAGhBP,GACCA,EAAW,OAAS,OAAUM,EAAY,KAAK,cAAc,EAI9DN,GACCA,EAAW,OAASK,EAAkB,QAAQ,aACjDE,EAAW,KAAK,cAAc,EAK5B,KAAK,UAAUD,CAAW,GAAK,KAAK,UAAUC,CAAU,GAC3DF,EAAkB,UAAU,OAAO,sBAAsB,EACzDA,EAAkB,aAAa,cAAe,OAAO,IAErDA,EAAkB,UAAU,IAAI,sBAAsB,EACtDA,EAAkB,aAAa,cAAe,MAAM,GAGrD,QAAQ,IAAK,cAAe,KAAK,UAAUC,CAAW,GACtD,QAAQ,IAAK,aAAc,KAAK,UAAUC,CAAU,EACtD,CAAE,EAED,IAAIC,EAA4B,SAAS,iBAAiB,0DAA0D,EAAE,OAElHR,IACCA,EAAW,OAAS,MAKxB,QAAQ,IAAKA,EAAW,SAIzBI,EAAA,SAAS,cAAc,YAAY,IAAnC,MAAAA,EAAsC,SAClCI,GAA6B,GAChCP,EAAgB,mBAAmB,aAAc,4EAA4E,CAE/H,EAGKD,GACHA,EAAW,iBAAiB,SAAUG,CAAW,EAGnDA,EAAa"}