import { useState } from "react"; import { Box, Link, Typography, useTheme, useMediaQuery, InputAdornment, IconButton, Button, Popover, TextareaAutosize, TextField, } from "@mui/material"; import { useParams } from "react-router-dom"; import { AnswerDraggableList } from "../AnswerDraggableList"; import { CropModal } from "@ui_kit/Modal/CropModal"; import { UploadImageModal } from "../UploadImage/UploadImageModal"; import AddImage from "@icons/questionsPage/addImage"; import Image from "@icons/questionsPage/image"; import { EnterIcon } from "../../../assets/icons/questionsPage/enterIcon"; import ButtonsOptionsAndPict from "../ButtonsOptionsAndPict"; import SwitchOptionsAndPict from "./switchOptionsAndPict"; import React from "react"; import { questionStore, updateQuestionsList } from "@root/questions"; import { ImageAddIcons } from "@icons/ImageAddIcons"; import { PointsIcon } from "@icons/questionsPage/PointsIcon"; import { MessageIcon } from "@icons/messagIcon"; import { DeleteIcon } from "@icons/questionsPage/deleteIcon"; import PlusImage from "@icons/questionsPage/plus"; import type { QuizQuestionVarImg } from "../../../model/questionTypes/varimg"; import { produce } from "immer"; interface Props { totalIndex: number; } export default function OptionsAndPicture({ totalIndex }: Props) { const [open, setOpen] = useState(false); const [opened, setOpened] = useState(false); const [switchState, setSwitchState] = useState("setting"); const [currentIndex, setCurrentIndex] = useState(0); const quizId = Number(useParams().quizId); const { listQuestions } = questionStore(); const theme = useTheme(); const isTablet = useMediaQuery(theme.breakpoints.down(1000)); const isMobile = useMediaQuery(theme.breakpoints.down(790)); const question = listQuestions[quizId][totalIndex] as QuizQuestionVarImg; const SSHC = (data: string) => { setSwitchState(data); }; const uploadImage = (files: FileList | null) => { if (files?.length) { const [file] = Array.from(files); const clonedContent = { ...question.content }; clonedContent.variants[currentIndex].extendedText = URL.createObjectURL(file); updateQuestionsList(quizId, totalIndex, { content: clonedContent, }); setOpen(false); setOpened(true); } }; return ( <> ( <> {!isMobile && ( { setCurrentIndex(index); setOpen(true); }} > {variant.extendedText ? ( ) : ( )} )} )} additionalMobile={(variant, index) => ( <> {isMobile && ( { setCurrentIndex(index); setOpen(true); }} sx={{ overflow: "hidden", display: "flex", alignItems: "center", m: "8px", position: "relative", borderRadius: "3px", }} > {variant.extendedText ? ( ) : ( )} + )} )} /> setOpen(false)} imgHC={uploadImage} /> setOpened(false)} picture={question.content.variants[currentIndex]?.extendedText} onCropPress={url => { const content = produce(question.content, draft => { draft.variants[currentIndex].extendedText = url; }); updateQuestionsList(quizId, totalIndex, { content, }); }} /> {!isMobile && ( + )} ), endAdornment: ( ), }} sx={{ "& .MuiInputBase-root": { padding: "13.5px", borderRadius: "10px", background: "#ffffff", height: "48px", }, "& .MuiOutlinedInput-notchedOutline": { border: "none", }, }} inputProps={{ sx: { fontSize: "18px", lineHeight: "21px", py: 0 }, }} /> {isMobile && ( + )} { const clonedContent = { ...question.content }; clonedContent.variants.push({ answer: "", hints: "", extendedText: "", }); updateQuestionsList(quizId, totalIndex, { content: clonedContent, }); }} > Добавьте ответ {isMobile ? null : ( <> или нажмите Enter )} ); }