import { Box, FormControl, IconButton, InputAdornment, InputBase, Typography, useMediaQuery, useTheme } from "@mui/material";
import { useState } from "react";
import CustomButton from "../../components/CustomButton";
import Message from "./Message";
import SendIcon from "../../components/icons/SendIcon";


export default function SupportChat() {
    const theme = useTheme();
    const upMd = useMediaQuery(theme.breakpoints.up("md"));
    const [messageText, setMessageText] = useState<string>("");

    return (
        <Box
            sx={{
                backgroundColor: upMd ? "white" : undefined,
                display: "flex",
                flexGrow: 1,
                maxHeight: upMd ? "443px" : undefined,
                borderRadius: "12px",
                p: upMd ? "20px" : undefined,
                gap: "40px",
                boxShadow: upMd ?
                    `0px 100px 309px rgba(210, 208, 225, 0.24), 
                        0px 41.7776px 129.093px rgba(210, 208, 225, 0.172525),
                        0px 22.3363px 69.0192px rgba(210, 208, 225, 0.143066), 
                        0px 12.5216px 38.6916px rgba(210, 208, 225, 0.12), 
                        0px 6.6501px 20.5488px rgba(210, 208, 225, 0.0969343), 
                        0px 2.76726px 8.55082px rgba(210, 208, 225, 0.0674749)`
                    :
                    undefined,
            }}
        >
            <Box
                sx={{
                    display: "flex",
                    alignItems: "start",
                    flexDirection: "column",
                    flexGrow: 1,
                }}
            >
                <Typography variant={upMd ? "h5" : "body2"} mb={"4px"}>Заголовок</Typography>
                <Typography sx={{
                    fontWeight: 400,
                    fontSize: "14px",
                    lineHeight: "17px",
                    color: theme.palette.grey2.main,
                    mb: upMd ? "9px" : "20px",
                }}>Создан: 15.09.22 08:39</Typography>
                <Box
                    sx={{
                        backgroundColor: "#ECECF3",
                        border: `1px solid ${theme.palette.grey2.main}`,
                        borderRadius: "10px",
                        overflow: "hidden",
                        width: "100%",
                        minHeight: "345px",
                        display: "flex",
                        flexGrow: 1,
                        flexDirection: "column",

                    }}
                >
                    <Box
                        sx={{
                            flexGrow: 1,
                            width: "100%",
                            borderBottom: `1px solid ${theme.palette.grey2.main}`,
                            px: upMd ? "20px" : "5px",
                            py: upMd ? "20px" : "13px",
                            display: "flex",
                            flexDirection: "column",
                            gap: upMd ? "20px" : "16px",
                            overflow: "auto",
                            height: "200px",
                        }}
                    >
                        <Message
                            text="Текст-заполнитель — это текст, который имеет "
                            time="16:40"
                            isSelf={false}
                        />
                        <Message
                            text="Текст-заполнитель — это текст, который имеет "
                            time="16:40"
                            isSelf={true}
                        />
                        <Message
                            text="Текст-заполнитель — это текст"
                            time="16:40"
                            isSelf={false}
                        />
                    </Box>
                    <FormControl>
                        <InputBase
                            value={messageText}
                            fullWidth
                            placeholder="Текст обращения"
                            id="message"
                            multiline
                            sx={{
                                width: "100%",
                                p: 0,
                            }}
                            inputProps={{
                                sx: {
                                    fontWeight: 400,
                                    fontSize: "16px",
                                    lineHeight: "19px",
                                    pt: upMd ? "13px" : "28px",
                                    pb: upMd ? "13px" : "24px",
                                    px: "19px",
                                    maxHeight: "calc(19px * 5)",
                                }
                            }}
                            onChange={e => setMessageText(e.target.value)}
                            endAdornment={!upMd &&
                                <InputAdornment position="end">
                                    <IconButton
                                        sx={{
                                            height: "45px",
                                            width: "45px",
                                            mr: "13px",
                                            p: 0,
                                        }}
                                    >
                                        <SendIcon />
                                    </IconButton>
                                </InputAdornment>
                            }
                        />
                    </FormControl>
                </Box>
            </Box>
            {upMd &&
                <Box sx={{ alignSelf: "end" }}>
                    <CustomButton
                        variant="contained"
                        sx={{
                            backgroundColor: theme.palette.brightPurple.main,
                        }}
                    >Отправить</CustomButton>
                </Box>
            }
        </Box>
    );
}