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CAAEC,IAAK,UAAWC,KAAM,mBAAoBC,MAAO,WACxDC,SAAA,EAEDC,EAAAA,EAAAA,KAAA,OAAKC,UAAU,YAAWF,UACxBC,EAAAA,EAAAA,KAAA,QAAAD,SAAO1C,EAAK6C,UAEdvB,EAAAA,EAAAA,MAACwB,EAAAA,EAAY,CAAAJ,SAAA,GACR1C,EAAK+C,YACNJ,EAAAA,EAAAA,KAACK,EAAAA,EAAM,CACLC,KAAK,SACLC,KAAK,QACLC,QAASA,KAAO,IAADC,GACC,QAAdA,EAAApD,EAAK+C,iBAAS,IAAAK,OAAA,EAAdA,EAAgBD,UAAWnD,EAAK+C,UAAUI,UAC1C7C,EAAiBF,EAAG,EACpBsC,SAED1C,EAAK+C,UAAUF,QAGpBF,EAAAA,EAAAA,KAACK,EAAAA,EAAM,CACLK,MAAO,CAAE,CAAC,UAASC,EAAAA,EAAQ,QAAU,SAAW,OAChDL,KAAK,UACLC,KAAK,QACLC,QAASA,KACPnD,EAAKuD,WAAWJ,UAChB7C,EAAiBF,EAAG,EACpBsC,SAED1C,EAAKuD,WAAWV,YAxChBzC,GA8CHO,EAAO,CACXP,GAAIA,EACJiB,MAAOA,GAGHT,EAAY,OAANI,QAAM,IAANA,GAAAA,EAAQR,OAAS,IAAIQ,EAAQL,GAAQ,CAACA,GAElDZ,EAAgBa,EAAI,EAGtBd,EAAgBkB,EAETA,CAAM,IAGFwC,EAAcxD,GAAqBK,EAAiBL,E","sources":["hooks/usePopup.tsx"],"sourcesContent":["import { ReactNode, useState } from 'react';\nimport { singletonHook } from 'react-singleton-hook';\nimport { isRtl } from 'utils/constants/app/rtl';\nimport { ModalPadding, ZINDEX_HIGH_1 } from 'utils/constants/app/ui';\nimport { isMobile } from 'utils/is-mobile';\nimport { Modal, ModalButtons } from 'components/Modal';\nimport { Button } from 'newcomponents/UI/Button';\n\ntype modalProps = {\n  title?: string;\n  text: string;\n  icon?: {\n    lib: string;\n    name: string;\n    theme: string;\n  };\n  successBtn: {\n    text: string;\n    onClick: Function;\n  };\n  cancelBtn?: {\n    text: string;\n    onClick?: Function;\n  };\n  closable?: boolean;\n};\nconst initialModalsValue: [] = [];\nlet currentModals: { id: number; modal: ReactNode }[] | [] = initialModalsValue;\n\nlet globalSetModals = (data: { id: number; modal: ReactNode }[] | []): void => {\n  console.error(\n    `you must usePopup before setting its state ${data[0].id ?? ''}`\n  );\n};\n\nlet globalModalAlert = (data: modalProps): void => {\n  console.error(`you must usePopup before setting its state ${data}`);\n};\n\nconst _removeFromModal = (id: number) => {\n  if (!currentModals.length) {\n    return;\n  }\n\n  const index = currentModals?.findIndex(item => item?.id === id);\n  const res = [...currentModals];\n  res.splice(index, 1);\n  globalSetModals(res);\n};\n\nexport const usePopup = singletonHook(initialModalsValue, () => {\n  const [modals, setModals] = useState<{ id: number; modal: ReactNode }[] | []>(\n    initialModalsValue\n  );\n\n  globalSetModals = data => {\n    currentModals = data;\n    setModals(data);\n  };\n\n  globalModalAlert = (data: modalProps) => {\n    const id = modals?.length ? modals?.length + 1 : 1;\n    const closable = data.closable ?? true;\n\n    const modal = (\n      <Modal\n        maxWidth={isMobile() ? '350px' : '420px'}\n        title={data.title}\n        visible={true}\n        closable={closable}\n        maskClosable={closable}\n        key={id}\n        centered\n        wrapperPadding={\n          isMobile() ? ModalPadding.MOBILE_12 : ModalPadding.DESKTOP_24\n        }\n        onCancel={() => {\n          _removeFromModal(id);\n        }}\n        zIndex={ZINDEX_HIGH_1}\n        image={\n          data.icon\n            ? { ...data.icon }\n            : { lib: 'generic', name: 'attentionGeneric', theme: 'colored' }\n        }\n      >\n        <div className=\"modalText\">\n          <span>{data.text}</span>\n        </div>\n        <ModalButtons>\n          {!!data.cancelBtn && (\n            <Button\n              type=\"cancel\"\n              size=\"large\"\n              onClick={() => {\n                data.cancelBtn?.onClick && data.cancelBtn.onClick();\n                _removeFromModal(id);\n              }}\n            >\n              {data.cancelBtn.text}\n            </Button>\n          )}\n          <Button\n            style={{ [`margin${isRtl ? 'Right' : 'Left'}`]: '8px' }}\n            type=\"primary\"\n            size=\"large\"\n            onClick={() => {\n              data.successBtn.onClick();\n              _removeFromModal(id);\n            }}\n          >\n            {data.successBtn.text}\n          </Button>\n        </ModalButtons>\n      </Modal>\n    );\n\n    const item = {\n      id: id,\n      modal: modal\n    };\n\n    const res = modals?.length ? [...modals, item] : [item];\n\n    globalSetModals(res);\n  };\n\n  currentModals = modals;\n\n  return modals;\n});\n\nexport const modalAlert = (data: modalProps) => globalModalAlert(data);\n"],"names":["initialModalsValue","currentModals","globalSetModals","data","_data$0$id","console","error","id","globalModalAlert","_removeFromModal","_currentModals","length","index","findIndex","item","res","splice","usePopup","singletonHook","modals","setModals","useState","_data$closable","closable","modal","_jsxs","Modal","maxWidth","isMobile","title","visible","maskClosable","centered","wrapperPadding","ModalPadding","MOBILE_12","DESKTOP_24","onCancel","zIndex","ZINDEX_HIGH_1","image","icon","lib","name","theme","children","_jsx","className","text","ModalButtons","cancelBtn","Button","type","size","onClick","_data$cancelBtn","style","isRtl","successBtn","modalAlert"],"sourceRoot":""}