{"version":3,"file":"PicturePicker-qC3kYVtG.js","sources":["../../../node_modules/@mui/icons-material/esm/AddAPhoto.js","../../../frontend/src/Components/Posts/Forms/PicturePicker.tsx"],"sourcesContent":["\"use client\";\n\nimport createSvgIcon from \"./utils/createSvgIcon.js\";\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nexport default createSvgIcon(/*#__PURE__*/_jsx(\"path\", {\n d: \"M3 4V1h2v3h3v2H5v3H3V6H0V4zm3 6V7h3V4h7l1.83 2H21c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H5c-1.1 0-2-.9-2-2V10zm7 9c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5m-3.2-5c0 1.77 1.43 3.2 3.2 3.2s3.2-1.43 3.2-3.2-1.43-3.2-3.2-3.2-3.2 1.43-3.2 3.2\"\n}), 'AddAPhoto');","import React, { useState } from 'react';\nimport { get, has } from 'lodash';\nimport { Box, Button, FormHelperText, Stack, Typography } from '@mui/material';\nimport { FormattedMessage, useIntl } from 'react-intl';\nimport { DirectUpload } from 'activestorage';\nimport {\n AddAPhoto,\n Delete as DeleteIcon,\n Edit as EditIcon,\n Help as HelpIcon,\n} from '@mui/icons-material';\n\nimport BaseImage from '../../DesignSystem/BaseImage';\nimport EmptyState from '../../DesignSystem/EmptyState';\nimport Tooltip from '../../DesignSystem/Tooltip';\nimport { cloudinaryImageUrl } from '../../../Services/Cloudinary';\nimport appsignal from '../../../Services/ErrorReportingService';\nimport withOptional from '../../../Utils/Posts/Form/withOptional';\n\nconst FILE_SIZE_LIMIT = 10; // MB\n\nfunction PicturePicker({\n uiSectionId,\n pictureS3Key,\n name = 'picture',\n filename,\n rounded = false,\n round = false,\n errors,\n register,\n setValue,\n willDestroy = false,\n label,\n tooltip = null,\n recommandedSize = [1200, 800],\n previewSize = [500, 500],\n previewRatio = 'fullHeight',\n setDisabledForm,\n setError,\n required = false,\n}: any) {\n const intl = useIntl();\n const [pictureObject, setPictureObject] = useState(null);\n const pictureUrl = cloudinaryImageUrl(\n pictureS3Key,\n `w_${previewSize[0]},h_${previewSize[1]},c_crop,c_fill,q_auto`,\n filename,\n );\n const labelOrPlaceholder = label || intl.formatMessage({ id: 'PICTURE_PICKER.COVER' });\n\n const handleTriggerFileInput = () => {\n document.getElementById(`${uiSectionId}-${name}-PickerInputFile`)?.click();\n };\n\n const handleDeletePicture = () => {\n setPictureObject(null);\n setValue(`${name}_attributes[_destroy]`, true);\n setValue(name, null);\n };\n\n const handleOnChangeFileInput = (event: any) => {\n const file = event.target.files[0];\n\n setDisabledForm(true);\n\n if (file.size > FILE_SIZE_LIMIT * 1024 * 1000) {\n setError(name, {\n type: 'manual',\n message: intl.formatMessage(\n { id: 'POSTS.FORM.PICTURE.ERRORS.FILE_SIZE' },\n { fileSize: FILE_SIZE_LIMIT },\n ),\n });\n setDisabledForm(false);\n } else {\n const upload = new DirectUpload(file, '/api/direct_uploads');\n\n upload.create((error: any, blob: any) => {\n if (error) {\n appsignal.sendError(error);\n setError(name, error);\n } else {\n setValue(name, blob.blob_signed_id);\n\n setDisabledForm(false);\n }\n });\n\n setPictureObject(URL.createObjectURL(file));\n setValue(`${name}_attributes[_destroy]`, false);\n }\n };\n\n const pictureUrlToRender = willDestroy ? null : pictureObject || pictureUrl;\n\n return (\n <>\n \n \n \n ({ display: 'flex', alignItems: 'center', gap: theme.spacing(0.5) })}\n gutterBottom\n component=\"label\"\n >\n {withOptional(labelOrPlaceholder, required)}\n\n {labelOrPlaceholder && (\n \n {tooltip && (\n <>\n {tooltip}\n
\n
\n \n )}\n
,\n b: (chunks: any) => {chunks},\n }}\n />\n \n }\n icon={}\n />\n )}\n \n
\n\n {\n e.target.value = null; // Allows to re-select the same file\n }}\n onChange={handleOnChangeFileInput}\n />\n\n {pictureUrlToRender && (\n \n )}\n\n {(willDestroy || !pictureUrlToRender) && (\n }\n >\n \n \n }\n />\n )}\n\n {pictureUrlToRender && (\n \n }\n >\n \n \n\n {!willDestroy && pictureUrlToRender && (\n }\n >\n \n \n )}\n \n )}\n\n \n {get(errors, `${name}.message`)}\n \n \n );\n}\n\nexport default PicturePicker;\n"],"names":["AddAPhoto","createSvgIcon","_jsx","FILE_SIZE_LIMIT","PicturePicker","_ref","uiSectionId","pictureS3Key","_ref$name","name","filename","_ref$rounded","rounded","_ref$round","round","errors","register","setValue","_ref$willDestroy","willDestroy","label","_ref$tooltip","tooltip","_ref$recommandedSize","recommandedSize","_ref$previewSize","previewSize","_ref$previewRatio","previewRatio","setDisabledForm","setError","_ref$required","required","intl","useIntl","_useState","useState","_useState2","_slicedToArray","pictureObject","setPictureObject","pictureUrl","cloudinaryImageUrl","concat","labelOrPlaceholder","formatMessage","id","handleTriggerFileInput","_document$getElementB","document","getElementById","click","handleDeletePicture","handleOnChangeFileInput","event","file","target","files","size","type","message","fileSize","upload","DirectUpload","create","error","blob","appsignal","sendError","blob_signed_id","URL","createObjectURL","pictureUrlToRender","React","createElement","Fragment","_extends","Box","display","alignItems","mb","Typography","variant","color","has","sx","theme","gap","spacing","gutterBottom","component","withOptional","Tooltip","title","FormattedMessage","values","width","height","br","b","chunks","icon","HelpIcon","fontSize","accept","className","style","onClick","e","value","onChange","BaseImage","src","ratio","alt","replace","EmptyState","action","Button","startIcon","Stack","direction","justifyContent","mt","EditIcon","DeleteIcon","FormHelperText","get"],"mappings":"mhBAIA,MAAAA,GAAeC,EAA2BC,GAAI,IAAC,OAAQ,CACrD,EAAG,oPACL,CAAC,EAAG,WAAW;01BCaf,IAAMC,EAAkB,GAExB,SAASC,GAAaC,EAmBd,CAlBNC,IAAAA,EAAWD,EAAXC,YACAC,EAAYF,EAAZE,aAAYC,EAAAH,EACZI,KAAAA,EAAID,IAAG,OAAA,UAASA,EAChBE,EAAQL,EAARK,SAAQC,EAAAN,EACRO,QAAAA,EAAOD,IAAG,OAAA,GAAKA,EAAAE,EAAAR,EACfS,MAAAA,EAAKD,IAAG,OAAA,GAAKA,EACbE,EAAMV,EAANU,OACAC,EAAQ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