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YhC,SAASS,iBAAiB,2CAE5C,IAAK,MAAMF,KAASwB,EAClBxB,EAAM0B,iBAAiB,QAAS,KAC9B3B,EAAsBC,GACtBO,EAAuBP,GACvBA,EAAM2B,cAAc,IAAIC,MAAM,uBAOlC,IAAK,MAAM5B,KAASyB,EAAW,CAC7B,MAAMI,EAAQpC,SAASC,cACrB,6CAA6CM,EAAMG,oDAErDH,EAAMM,gBAAkBuB,EACpB7B,EAAMM,gBACQN,EAAMS,QAAQ,WACtBS,MAAO,EAEnB,CAEA/B,OAAO2C,SAAWb,EAClBA,GACF,CAEAc,GAEAtC,SAASC,cAAc,yCAAyCgC,iBAAiB,QAAS,KACxFpC,GAAkBD,I","sources":["webpack://mano-tiki-tia/./static/js/recipelist.js"],"sourcesContent":["let shouldCollapseSidebarOnResize = window.innerWidth < 768\nlet isMobileFilterOpen = false\n\nfunction hideOrShowFilter(isOpen) {\n  const el = document.querySelector(\".recipelist__results\")\n  const sideBar = document.querySelector(\".recipelist__sidebar\")\n  isMobileFilterOpen = isOpen\n  if (isOpen) {\n    el.classList.add(\"d-none\")\n    sideBar.classList.add(\"open\")\n  } else {\n    el.classList.remove(\"d-none\")\n    sideBar.classList.remove(\"open\")\n  }\n}\n\nfunction hideSubmitButton() {\n  // if we've got js, then get rid of the submit button, this form auto submits on changes.\n  // This lives in a function because otherwise when hitting the back button in the browser, sometimes\n  // filterSubmitButton is already defined and then we get js exceptions\n  const filterSubmitButton = document.querySelector(\"#ingredient-filter-form button[type=submit]\")\n  filterSubmitButton.style.display = \"none\"\n  filterSubmitButton.disabled = true\n}\n\nfunction toggleChildCheckboxes(input) {\n  const children = document.querySelectorAll(\n    `.filter-form-child-group[data-childrenfor=${input.id}] input[name=ingredients]`,\n  )\n  for (const childInput of children) {\n    childInput.checked = false\n    childInput.indeterminate = false\n  }\n}\n\nfunction toggleParentCheckboxes(input) {\n  // get the wrapper \"childrenfor\" element, grab it's childrenfor value\n  // and then set that element to checked=False, indeterminate=True\n  const childGrouper = input.closest(`.filter-form-child-group`)\n  if (childGrouper) {\n    const parentId = childGrouper.dataset.childrenfor\n    const parent = document.querySelector(`#${parentId}`)\n    if (parent) {\n      let noChildrenChecked = true\n      if (!input.checked) {\n        const siblingInputs = childGrouper.querySelectorAll(\"input[name=ingredients]\")\n        // TODO: if all children are checked, then uncheck them and check the parent\n        // TODO: possibly, if parent is checked, then check all children and on form submit\n        //       clean up the extra unneeded params. We only need to send that the parent was checked\n        //       to the server.\n        for (const sibling of siblingInputs) {\n          if (sibling.checked) {\n            noChildrenChecked = false\n          }\n        }\n      }\n      parent.indeterminate = !noChildrenChecked || input.checked\n      parent.checked = false\n      toggleParentCheckboxes(parent)\n    } // end if parent\n  }\n}\n\nfunction resizeFn() {\n  if (window.innerWidth >= 768) {\n    document.querySelector(\".recipelist__sidebar__filters\").open = true\n    isMobileFilterOpen = false\n    shouldCollapseSidebarOnResize = true\n    hideOrShowFilter(false)\n  } else if (shouldCollapseSidebarOnResize) {\n    document.querySelector(\".recipelist__sidebar__filters\").open = false\n    shouldCollapseSidebarOnResize = false // don't do it on EVERY resize, just the first time we go from >= 768 to < 768;\n    hideOrShowFilter(false)\n  }\n}\n\nfunction initPage() {\n  hideSubmitButton()\n  const ingredientFilterCheckboxes = document.querySelectorAll(\n    \".ingredient-filters input[name=ingredients]\",\n  )\n  const unchecked = document.querySelectorAll('input[name=\"ingredients\"]:not(:checked)')\n\n  for (const input of ingredientFilterCheckboxes) {\n    input.addEventListener(\"click\", () => {\n      toggleChildCheckboxes(input)\n      toggleParentCheckboxes(input)\n      input.dispatchEvent(new Event(\"submitFilterForm\"))\n    })\n  }\n\n  // find any unchecked inputs and see if they have any checked children. If so, mark as indeterminate.\n  // There must be something more efficient, but this works for now. It does result in a small amount of flash\n  // as the property gets set, but there doesn't seem to be anything to do about that.\n  for (const input of unchecked) {\n    const child = document.querySelector(\n      `.filter-form-child-group[data-childrenfor=${input.id}] input[name=\"ingredients\"]:checked:last-child`,\n    )\n    input.indeterminate = !!child\n    if (input.indeterminate) {\n      const details = input.closest(\"details\")\n      details.open = true\n    }\n  }\n\n  window.onresize = resizeFn\n  resizeFn()\n}\n\ninitPage()\n\ndocument.querySelector(\".recipelist__sidebar__filters summary\").addEventListener(\"click\", () => {\n  hideOrShowFilter(!isMobileFilterOpen)\n})\n"],"names":["shouldCollapseSidebarOnResize","window","innerWidth","isMobileFilterOpen","hideOrShowFilter","isOpen","el","document","querySelector","sideBar","classList","add","remove","toggleChildCheckboxes","input","children","querySelectorAll","id","childInput","checked","indeterminate","toggleParentCheckboxes","childGrouper","closest","parentId","dataset","childrenfor","parent","noChildrenChecked","siblingInputs","sibling","resizeFn","open","filterSubmitButton","style","display","disabled","hideSubmitButton","ingredientFilterCheckboxes","unchecked","addEventListener","dispatchEvent","Event","child","onresize","initPage"],"ignoreList":[],"sourceRoot":""}