import moment from 'moment';
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 { 
  useSetHeaderTitle,
  useSetHeaderType,
  useSetFooterMode,
  useSetOnBack
} from '@/widgets/sub-layout/use-sub-layout';

export const QnaDetailPage = () => {
  const { navigate } = useNavigate();
  const location = useLocation();

  const [statusCode, setStatusCode] = useState<string>('');
  const [statusName, setStatusName] = useState<string>('');
  const [requestDate, setRequestDate] = useState<string>('');
  const [requestName, setRequestName] = useState<string>('');
  const [title, setTitle] = useState<string>('');
  const [contents, setContents] = useState<string>('');
  const [answer, setAnswer] = useState<string>('');

  useSetHeaderTitle('1:1 문의');
  useSetHeaderType(HeaderType.LeftArrow);
  useSetFooterMode(false);
  useSetOnBack(() => {
    navigate(PATHS.support.faq.list);
  });

  useEffect(() => {
    setStatusCode(location?.state.statusCode);
    setStatusName(location?.state.statusName);
    setRequestDate(location?.state.requestDate);
    setRequestName(location?.state.requestName);
    setTitle(location?.state.title);
    setContents(location?.state.contents);
    setAnswer(location?.state.answer);
  }, []);

  return (
    <>
      <main>
        <div className="tab-content">
          <div className="tab-pane active">
            <div className="inq-detail">
              <div className="inq-detail__head">
                <div className="inq-detail__row">
                  <span className="inq-badge">제목</span>
                  <span className="inq-head-text bold">보증보험 가입 완료에 따른 한도증액 요청...</span>
                </div>
                <div className="inq-detail__row">
                  <span className="inq-badge">유형</span>
                  <span className="inq-head-text">한도/보증보험 문의</span>
                </div>
                <div className="inq-detail__row">
                  <span className="inq-badge">등록일</span>
                  <span className="inq-head-text">{ moment(requestDate).format('YYYY.MM.DD') }</span>
                </div>
                <div className="inq-detail__row">
                  <span className="inq-badge">답변일</span>
                  <span className="inq-head-text">2025.07.31</span>
                </div>
              </div>
              <div className="inq-detail__divider"></div>
              <div className="inq-detail__section">
                <div className="inq-detail__section-title">문의 답변</div>
                <div className="inq-detail__body">{ answer }</div>
              </div>
              <div className="inq-detail__section">
                <div className="inq-detail__section-title">문의 내용</div>
                <div className="inq-detail__box">
                  <div className="inq-detail__kv">
                    <div className="k">제목</div>
                    <div className="v">{ title }</div>
                  </div>
                  <div className="inq-detail__kv">
                    <div className="k">내용</div>
                    <div className="v">{ contents }</div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </main>
    </>
  );
};