import moment from 'moment';
import React, { useState } from 'react';
import { Box, Card, Icon, Stack, colors, Link, Avatar, CardMedia, CardHeader, CardContent, Typography, CircularProgress, useMediaQuery } from '@dashup/ui';
// let context
let DashupUIContext = null;
// create dashup grid body
const DashupUIChatEmbed = (props = {}) => {
// is mobile
const isMobile = useMediaQuery('(max-width:800px)');
// get duration
const getDuration = (time) => {
// return duration
const duration = moment.duration(time * 100);
// humanize
return duration.humanize();
};
// render body
const renderBody = (data) => {
// check type
if (props.embed.type === 'note') return (
) }
/>
{ props.embed.data?.body }
);
// check type
if (props.embed.type === 'sms') return (
) }
/>
{ props.embed.data?.body }
);
// check type
if (props.embed.type === 'phone') return (
) }
subheader={ `From: ${props.embed.data?.from?.number}` }
/>
);
// check type
if (props.embed.type === 'email') return (
) }
subheader={ props.embed.data?.subject }
/>
);
// return card
return (
)
) }
subheader={ (
{ !!props.embed?.data?.provider?.url && (
{ props.embed.data.provider.name }
) }
{ !!props.embed.data?.author?.url && (
{ props.embed.data.author.name }
) }
{ !!props.embed.data?.duration && (
{ getDuration(props.embed.data.duration) }
) }
) }
/>
{ !!props.embed.loading && (
) }
{ !!props.embed.data?.html && (
) }
);
};
// return jsx
return props.noChat ? renderBody(props) : (
{ (data) => {
// render body
return renderBody(data);
} }
);
};
// export default page menu
export default (ctx) => {
// use context
DashupUIContext = ctx;
// return actual component
return DashupUIChatEmbed;
};