import moment from 'moment';
import { useTranslation } from 'react-i18next';
import { SectionTitleArrow } from '@/entities/common/ui/section-title-arrow';
import { InfoSectionKeys, InfoSectionProps } from '../../model/types';
import { SlideDown } from 'react-slidedown';
import 'react-slidedown/lib/slidedown.css';

export const DetailInfoSection = ({
  transactionCategory,
  detailInfo,
  isOpen,
  onClickToOpenInfo
}: InfoSectionProps) => {
  const { t } = useTranslation();
  
  const onClickToSetOpenInfo = () => {
    if(!!onClickToOpenInfo){
      onClickToOpenInfo(InfoSectionKeys.Detail);
    }
  };
  
  return (
    <>
      <div className="txn-section">
        <div
          className="section-title with-toggle"
          onClick={ () => onClickToSetOpenInfo() }
        >
          {t('transaction.sections.detailInfo')} <SectionTitleArrow isOpen={ isOpen }></SectionTitleArrow>
        </div>
        <SlideDown className={'my-dropdown-slidedown'}>
        { !!isOpen &&
          <ul className="kv-list">
            <li className="kv-row">
              <span className="k">{t('transaction.fields.cancelDate')}</span>
              <span className="v">{ detailInfo?.cancelDate? moment(detailInfo?.cancelDate).format('YYYY.MM.DD'): '' }</span>
            </li>
            <li className="kv-row">
              <span className="k">{t('transaction.fields.cancelApprovalNumber')}</span>
              <span className="v">{ detailInfo?.cancelApprovalNumber }</span>
            </li>
            <li className="kv-row">
              <span className="k">{t('transaction.fields.receiptInfo')}</span>
              <span className="v">{ detailInfo?.receiptInfo }</span>
            </li>
            <li className="kv-row">
              <span className="k">{t('transaction.fields.tid')}</span>
              <span className="v">{ detailInfo?.tid }</span>
            </li>
            <li className="kv-row">
              <span className="k">{t('transaction.fields.transactionId')}</span>
              <span className="v">{ detailInfo?.merchantTid }</span>
            </li>
            <li className="kv-row">
              <span className="k">{t('transaction.fields.subMallName')}</span>
              <span className="v">{ detailInfo?.subMallName }</span>
            </li>
            <li className="kv-row">
              <span className="k">{t('transaction.fields.subMallBusinessNumber')}</span>
              <span className="v">{ detailInfo?.subMallBusinessNumber }</span>
            </li>
            <li className="kv-row">
              <span className="k">{t('transaction.fields.issueChannel')}</span>
              <span className="v">{ detailInfo?.issueChannel }</span>
            </li>
            <li className="kv-row">
              <span className="k">{t('transaction.fields.failureReason')}</span>
              <span className="v">{ detailInfo?.failureReason }</span>
            </li>
          </ul>
        }
        </SlideDown>
      </div>
    </>
  )
};