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B,EAAKsB,aAAa,iBAC5BF,EAAmBpB,EAAKsB,aAAa,kCACrCN,EAAW,CAAEC,WAAUC,UAASE,qBAClC,GAEJ,IAGSmB,QAAQvC,EAAM,CAAEwC,YAAY,GACvC,CACF,IACC,CAACjC,GAAe,C","sources":["webpack:///./app/javascript/packs/schoolReviewFormEntryComponent.jsx"],"sourcesContent":["import React, { useEffect, useState } from 'react';\nimport { createRoot } from 'react-dom/client';\n\nimport { SchoolReviewForm } from '../main-app/components/ReviewForm';\nimport stores from '../main-app/stores';\n\nconst SchoolReviewFormEntryComponent = ({ node }) => {\n  const root = createRoot(node);\n  const bottomReviewButtons = document.getElementsByClassName('vv-post-rating-btn');\n  const [isFormVisible, setIsFormVisible] = useState(false);\n\n  if (bottomReviewButtons) {\n    // eslint-disable-next-line no-plusplus\n    for (let i = 0; i < bottomReviewButtons.length; i++) {\n      bottomReviewButtons[i].addEventListener('click', () => {\n        setIsFormVisible(true);\n      });\n    }\n  }\n\n  useEffect(() => {\n    if (window.location.hash === '#post-review') {\n      setIsFormVisible(true);\n    }\n  }, []);\n\n  const renderForm = ({\n    schoolId, placeId, userSchools, minCommentLength,\n  }) => {\n    if (!isFormVisible) return;\n    root.render(\n      <SchoolReviewForm minCommentLength={minCommentLength} schoolId={schoolId} userSchools={userSchools} placeId={placeId} />,\n    );\n  };\n\n  if (!node) return;\n\n  let schoolId = node.getAttribute('data-school-id');\n  let placeId = node.getAttribute('data-place-id');\n  let minCommentLength = node.getAttribute('data-school-min-comment-length');\n  useEffect(() => {\n    if (schoolId) {\n      renderForm({ schoolId, placeId, minCommentLength });\n    } else {\n      const userSchools = JSON.parse(node.getAttribute('data-user-schools'));\n      if (userSchools) {\n        schoolId = userSchools[0].id;\n        placeId = userSchools[0].placeId;\n        minCommentLength = userSchools[0].min_comment_length;\n        renderForm({\n          schoolId, userSchools, placeId, minCommentLength,\n        });\n      } else {\n        const callback = function (mutationsList) {\n          mutationsList.forEach((mutation) => {\n            if (mutation.type === 'attributes' && mutation.attributeName === 'data-school-id') {\n              root.unmount();\n              stores.schoolReviewStore.isSent = false;\n              stores.meetingStore.meetingSubjects = [];\n\n              schoolId = node.getAttribute('data-school-id');\n              placeId = node.getAttribute('data-place-id');\n              minCommentLength = node.getAttribute('data-school-min-comment-length');\n              renderForm({ schoolId, placeId, minCommentLength });\n            }\n          });\n        };\n\n        const observer = new MutationObserver(callback);\n        observer.observe(node, { attributes: true });\n      }\n    }\n  }, [isFormVisible]);\n};\n\nexport default SchoolReviewFormEntryComponent;\n"],"names":["node","root","createRoot","bottomReviewButtons","document","getElementsByClassName","useState","isFormVisible","setIsFormVisible","i","length","addEventListener","useEffect","window","location","hash","renderForm","schoolId","placeId","userSchools","minCommentLength","render","getAttribute","JSON","parse","id","min_comment_length","MutationObserver","mutationsList","forEach","mutation","type","attributeName","unmount","stores","schoolReviewStore","isSent","meetingStore","meetingSubjects","observe","attributes"],"sourceRoot":""}