import { useEffect, useState } from 'react';
import { PATHS } from '@/shared/constants/paths';
import { useLocation } from 'react-router';
import { useNavigate } from '@/shared/lib/hooks/use-navigate';
import { HeaderType } from '@/entities/common/model/types';
import { useTranslation } from 'react-i18next';
import {
  useSetHeaderTitle,
  useSetHeaderType,
  useSetFooterMode,
  useSetOnBack
} from '@/widgets/sub-layout/use-sub-layout';

export const FaqDetailPage = () => {
  const { navigate } = useNavigate();
  const location = useLocation();
  const { t } = useTranslation();

  const [cursorId, setCursorId] = useState<number>(0);
  const [seq, setSeq] = useState<string>('');
  const [category, setCategory] = useState<string>('');
  const [title, setTitle] = useState<string>('');
  const [contents, setContents] = useState<string>('');

  useSetHeaderTitle(t('support.faq.title'));
  useSetHeaderType(HeaderType.LeftArrow);
  useSetFooterMode(false);
  useSetOnBack(() => {
    navigate(PATHS.support.faq.list);
  });

  useEffect(() => {
    setCursorId(location?.state.cursorId);
    setSeq(location?.state.seq);
    setCategory(location?.state.category);
    setTitle(location?.state.title);
    setContents(location?.state.contents);
  }, []);
  return (
    <>
      <main>
        { contents &&
          <div className="tab-content">
            <div className="tab-pane sub active">
              <div className="faq-detail">
                <div className="faq-detail__title">{ title }</div>
                <div className="faq-detail__divider"></div>
                <div className="faq-detail__body" dangerouslySetInnerHTML={{ __html: contents || '' }}></div>
              </div>
            </div>
          </div>
        }
      </main>
    </>
  );
};