/* eslint-disable react-hooks/exhaustive-deps */ import React, { useContext, useEffect } from "react"; import dynamic from "next/dynamic"; const Input = dynamic(() => import("../Input")); const Button = dynamic(() => import("../Button")); import { BodyProps, Context } from "../../contexts/Context"; import styles from "./Body.module.scss"; import { FiSend } from "react-icons/fi"; import { deviceCompanyOptions, firstOptions, otherOptions } from "../../services/api"; export default function Body({ color, baseUrl, ownerName, whatsappNumber, backgroundColor, }: BodyProps) { const containerRef = React.useRef(null); const { step, userName, inputValue, deviceModel, lastMessages, deviceCompany, deviceProblem, otherMessages, initialMessages, otherMessagesText, firstOptionSelected, othersOptionSelected, technicalAssitanceMessages, deviceCompanyOptionSelected, handleGetContainerRef, handleSelectFirstOptions, handleSelectOthersOptions, handleSelectDeviceCompanyOptions, } = useContext(Context); const technicalAssistanceWhatsappMessage = `https://wa.me/${whatsappNumber}?text=Olá,%0D%0AEstou precisando de ajuda referente à:%0D%0A*Assistência Técnica*.%0D%0A%0D%0A*Minhas informações*%0D%0A Nome: ${userName}%0D%0A Marca: ${deviceCompany}%0D%0A Modelo: ${deviceModel}%0D%0A Problema: ${deviceProblem}%0D%0A%0D%0A- Não se preocupe, em breve um de nossos colaboradores irá te atender.%0D%0A%0D%0AMensagem gerada automaticamente através de:%0D%0A${baseUrl}%0D%0A${new Date().toLocaleString()} `; const othersWhatsappMessage = `https://wa.me/${whatsappNumber}?text=Olá,%0D%0AEstou precisando de ajuda referente à:%0D%0A*Outros*.%0D%0A%0D%0A*Minhas informações*%0D%0A Nome: ${userName}%0D%0A Assunto: ${otherMessagesText}%0D%0A%0D%0A- Não se preocupe, em breve um de nossos colaboradores irá te atender.%0D%0A%0D%0AMensagem gerada automaticamente através de:%0D%0A${baseUrl}%0D%0A${new Date().toLocaleString()} `; useEffect(() => { handleGetContainerRef(containerRef as any); }, [containerRef]); return (
{initialMessages?.slice(0, 1).map((message) => { return (
{message.text.split("|")[0]} {message.text.split("|")[1]}
); })} {userName && (
)} {initialMessages?.slice(1, step).map((message) => { return (

{message.text.split("|")[0]},

{message.text.split("|")[1]}

); })} {step >= 2 && (
{firstOptions.map((option) => { return ( ); })}
)} {firstOptionSelected === 1 && ( <> {step >= 3 && ( <> {technicalAssitanceMessages?.slice(0, 1).map((message) => { return (

{message.text.split("|")[0]}

{message.text.split("|")[1]} {message.text.split("|")[2]} {message.text.split("|")[3]}
); })}
{deviceCompanyOptions.map((option) => { return ( ); })}
)} {step >= 4 && deviceCompanyOptionSelected !== 0 && ( <> {technicalAssitanceMessages?.slice(1, 2).map((message) => { return (

{message.text.split("|")[0]}

{message.text.split("|")[1]} {message.text.split("|")[2]} {message.text.split("|")[3]}
); })} {deviceModel && (
)} )} {step >= 5 && deviceModel && deviceCompanyOptionSelected && ( <> {technicalAssitanceMessages?.slice(2, 3).map((message) => { return (

{message.text.split("|")[0]},

{message.text.split("|")[1]} {message.text.split("|")[2]} {message.text.split("|")[3]}
); })} {deviceProblem && (
)} )} {step >= 6 && deviceProblem && deviceModel && ( <>

{lastMessages.text.split("|")[0]}

{lastMessages.text.split("|")[1]}

)} )} {firstOptionSelected === 2 && ( <> {step >= 2 && ( <> {otherMessages?.slice(0, 1).map((message) => { return (

{message.text}

); })}
{otherOptions.map((option) => { return ( ); })}
)} {step >= 3 && othersOptionSelected === 3 && otherMessages?.slice(1, 2).map((message) => { return (

{message.text.split("|").map((item) => { return

🗓️{item}

; })}

); })} {step >= 3 && othersOptionSelected === 4 && otherMessages?.slice(2, 3).map((message) => { return (

{message.text.split("|")[0]}:


{message.text .split("|") ?.slice(1) .map((item) => { return (

- {item}

); })}
); })} {step >= 3 && othersOptionSelected === 5 && ( <> {otherMessages?.slice(3, 4).map((message) => { return (

{message.text}

); })} {otherMessagesText && (
)} )} {step >= 4 && otherMessagesText && ( <>

{lastMessages.text.split("|")[0]}

{lastMessages.text.split("|")[1]}

)} )}
); }