import moment from 'moment';
import 'moment/dist/locale/ko';
import { ListDateGroupProps } from '../model/types';
import { ListItem } from '../ui/list-item';

export const ListDateGroup = ({
  additionalServiceCategory,
  date,
  items,
  mid
}: ListDateGroupProps) => {
  moment.locale('ko');
  const getStateDate = () => {
    let stateDate = moment(date).format('YY.MM.DD(ddd)');
    return stateDate;
  };

  const getListItem = () => {
    let rs = [];
    if(!!items && items.length>0){
      for(let i=0;i<items.length;i++){
        let key = 'ListItem-'+i;
        rs.push(
          <ListItem
            additionalServiceCategory={ additionalServiceCategory }
            key={ key }
            mid={ mid }
            tid={ items[i]?.tid }
            paymentDate= { items[i]?.paymentDate}
            paymentStatus={ items[i]?.paymentStatus}

            requestDate={ items[i]?.requestDate }
            bankName={ items[i]?.bankName}
            accountNo={ items[i]?.accountNo }
            resultStatus={ items[i]?.resultStatus }

            transactionId={ items[i]?.transactionId }
            customerName={ items[i]?.customerName }
            status={ items[i]?.status }
            channel={ items[i]?.channel }
            amount={ items[i]?.amount }
            sendDate={ items[i]?.sendDate }
            transactionDate={ items[i]?.transactionDate }
          ></ListItem>
        )
      }  
    }
    
    return rs;
  };

  return (
    <>
      <div className="date-group">
        <div className="date-header">{ getStateDate() }</div>
        { getListItem() }
      </div>
    </>
  );
};