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

export const ListDateGroup = ({
  transactionCategory,
  date,
  items
}: 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
            transactionCategory={ transactionCategory }
            key={ key }
            tid={ items[i]?.tid }
            mid={ items[i]?.mid }
            stateDate={ items[i]?.stateDate }
            stateCode={ items[i]?.stateCode }
            stateName={ items[i]?.stateName }
            installmentMonth={ items[i]?.installmentMonth }
            serviceCode={ items[i]?.serviceCode }
            serviceName={ items[i]?.serviceName }
            serviceDetailName={ items[i]?.serviceDetailName }
            goodsAmount={ items[i]?.goodsAmount }

            id={ items[i]?.id }
            amount={ items[i]?.amount }
            customerName={ items[i]?.customerName }
            issueNumber={ items[i]?.issueNumber }
            issueStatus={ items[i]?.issueStatus }
            paymentMethod={ items[i]?.paymentMethod }
            processResult={ items[i]?.processResult }
            transactionDateTime={ items[i]?.transactionDateTime }

            transactionAmount={ items[i]?.transactionAmount }
            deliveryStatus={ items[i]?.deliveryStatus }
            settlementStatus={ items[i]?.settlementStatus }
            cancelStatus={ items[i]?.cancelStatus }

            billKey={ items[i]?.billKey }
            orderNumber={ items[i]?.orderNumber }
          ></ListItem>
        )
      }  
    }
    
    return rs;
  };

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