import { useState } from 'react'
import PropTypes from 'prop-types'
import { Tabs, Tab, Box } from '@mui/material'
import { CopyBlock, atomOneDark } from 'react-code-blocks'
// Project import
import { CheckboxInput } from '@/ui-component/checkbox/Checkbox'
// Const
import { baseURL } from '@/store/constant'
function TabPanel(props) {
const { children, value, index, ...other } = props
return (
{value === index && {children}}
)
}
TabPanel.propTypes = {
children: PropTypes.node,
index: PropTypes.number.isRequired,
value: PropTypes.number.isRequired
}
function a11yProps(index) {
return {
id: `attachment-tab-${index}`,
'aria-controls': `attachment-tabpanel-${index}`
}
}
const embedPopupHtmlCode = (chatflowid) => {
return ``
}
const embedPopupReactCode = (chatflowid) => {
return `import { BubbleChat } from 'flowise-embed-react'
const App = () => {
return (
);
};`
}
const embedFullpageHtmlCode = (chatflowid) => {
return `
`
}
const embedFullpageReactCode = (chatflowid) => {
return `import { FullPageChat } from "flowise-embed-react"
const App = () => {
return (
);
};`
}
const buttonConfig = (isReact = false) => {
return isReact
? `button: {
backgroundColor: "#3B81F6",
right: 20,
bottom: 20,
size: 48, // small | medium | large | number
dragAndDrop: true,
iconColor: "white",
customIconSrc: "https://raw.githubusercontent.com/walkxcode/dashboard-icons/main/svg/google-messages.svg",
}`
: `button: {
backgroundColor: "#3B81F6",
right: 20,
bottom: 20,
size: 48, // small | medium | large | number
dragAndDrop: true,
iconColor: "white",
customIconSrc: "https://raw.githubusercontent.com/walkxcode/dashboard-icons/main/svg/google-messages.svg",
}`
}
const tooltipConfig = (isReact = false) => {
return isReact
? `tooltip: {
showTooltip: true,
tooltipMessage: 'Hi There 👋!',
tooltipBackgroundColor: 'black',
tooltipTextColor: 'white',
tooltipFontSize: 16,
}`
: `tooltip: {
showTooltip: true,
tooltipMessage: 'Hi There 👋!',
tooltipBackgroundColor: 'black',
tooltipTextColor: 'white',
tooltipFontSize: 16,
}`
}
const chatwindowConfig = (isReact = false) => {
return isReact
? `chatWindow: {
showTitle: true,
title: 'Flowise Bot',
titleAvatarSrc: 'https://raw.githubusercontent.com/walkxcode/dashboard-icons/main/svg/google-messages.svg',
welcomeMessage: 'Hello! This is custom welcome message',
errorMessage: 'This is a custom error message',
backgroundColor: "#ffffff",
height: 700,
width: 400,
fontSize: 16,
poweredByTextColor: "#303235",
botMessage: {
backgroundColor: "#f7f8ff",
textColor: "#303235",
showAvatar: true,
avatarSrc: "https://raw.githubusercontent.com/zahidkhawaja/langchain-chat-nextjs/main/public/parroticon.png",
},
userMessage: {
backgroundColor: "#3B81F6",
textColor: "#ffffff",
showAvatar: true,
avatarSrc: "https://raw.githubusercontent.com/zahidkhawaja/langchain-chat-nextjs/main/public/usericon.png",
},
textInput: {
placeholder: 'Type your question',
backgroundColor: '#ffffff',
textColor: '#303235',
sendButtonColor: '#3B81F6',
maxChars: 50,
maxCharsWarningMessage: 'You exceeded the characters limit. Please input less than 50 characters.',
autoFocus: true, // If not used, autofocus is disabled on mobile and enabled on desktop. true enables it on both, false disables it on both.
},
feedback: {
color: '#303235',
},
footer: {
textColor: '#303235',
text: 'Powered by',
company: 'Flowise',
companyLink: 'https://flowiseai.com',
}
}`
: `chatWindow: {
showTitle: true,
title: 'Flowise Bot',
titleAvatarSrc: 'https://raw.githubusercontent.com/walkxcode/dashboard-icons/main/svg/google-messages.svg',
welcomeMessage: 'Hello! This is custom welcome message',
errorMessage: 'This is a custom error message',
backgroundColor: "#ffffff",
height: 700,
width: 400,
fontSize: 16,
poweredByTextColor: "#303235",
botMessage: {
backgroundColor: "#f7f8ff",
textColor: "#303235",
showAvatar: true,
avatarSrc: "https://raw.githubusercontent.com/zahidkhawaja/langchain-chat-nextjs/main/public/parroticon.png",
},
userMessage: {
backgroundColor: "#3B81F6",
textColor: "#ffffff",
showAvatar: true,
avatarSrc: "https://raw.githubusercontent.com/zahidkhawaja/langchain-chat-nextjs/main/public/usericon.png",
},
textInput: {
placeholder: 'Type your question',
backgroundColor: '#ffffff',
textColor: '#303235',
sendButtonColor: '#3B81F6',
maxChars: 50,
maxCharsWarningMessage: 'You exceeded the characters limit. Please input less than 50 characters.',
autoFocus: true, // If not used, autofocus is disabled on mobile and enabled on desktop. true enables it on both, false disables it on both.
},
feedback: {
color: '#303235',
},
footer: {
textColor: '#303235',
text: 'Powered by',
company: 'Flowise',
companyLink: 'https://flowiseai.com',
}
}`
}
const embedPopupHtmlCodeCustomization = (chatflowid) => {
return ``
}
const embedPopupReactCodeCustomization = (chatflowid) => {
return `import { BubbleChat } from 'flowise-embed-react'
const App = () => {
return (
);
};`
}
const embedFullpageHtmlCodeCustomization = (chatflowid) => {
return `
`
}
const embedFullpageReactCodeCustomization = (chatflowid) => {
return `import { FullPageChat } from "flowise-embed-react"
const App = () => {
return (
);
};`
}
const EmbedChat = ({ chatflowid }) => {
const codes = ['Popup Html', 'Fullpage Html', 'Popup React', 'Fullpage React']
const [value, setValue] = useState(0)
const [embedChatCheckboxVal, setEmbedChatCheckbox] = useState(false)
const onCheckBoxEmbedChatChanged = (newVal) => {
setEmbedChatCheckbox(newVal)
}
const handleChange = (event, newValue) => {
setValue(newValue)
}
const getCode = (codeLang) => {
switch (codeLang) {
case 'Popup Html':
return embedPopupHtmlCode(chatflowid)
case 'Fullpage Html':
return embedFullpageHtmlCode(chatflowid)
case 'Popup React':
return embedPopupReactCode(chatflowid)
case 'Fullpage React':
return embedFullpageReactCode(chatflowid)
default:
return ''
}
}
const getCodeCustomization = (codeLang) => {
switch (codeLang) {
case 'Popup Html':
return embedPopupHtmlCodeCustomization(chatflowid)
case 'Fullpage Html':
return embedFullpageHtmlCodeCustomization(chatflowid)
case 'Popup React':
return embedPopupReactCodeCustomization(chatflowid)
case 'Fullpage React':
return embedFullpageReactCodeCustomization(chatflowid)
default:
return ''
}
}
return (
<>
{codes.map((codeLang, index) => (
))}
{codes.map((codeLang, index) => (
{(value === 0 || value === 1) && (
<>
Paste this anywhere in the {``} tag of your html file.
You can also specify a
version
: {`https://cdn.jsdelivr.net/npm/flowise-embed@/dist/web.js`}
>
)}
{embedChatCheckboxVal && (
)}
))}
>
)
}
EmbedChat.propTypes = {
chatflowid: PropTypes.string
}
export default EmbedChat