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

export const ListDateGroup = ({
  date,
  items
}: ListDateGroupProps) => {
  moment.locale('ko');
  const getStateDate = () => {
    let stateDate = moment(date).format('YY.MM');
    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
            key={ key }
            tid={ items[i]?.tid }
            pname={ items[i]?.pname }
            userid={ items[i]?.userid }
            idate={ items[i]?.idate }
            kind={ items[i]?.kind }
            amount={ items[i]?.amount }
          ></ListItem>
        )
      }  
    }
    
    return rs;
  };

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