import { AtListItem } from 'taro-ui';
import repair from '@/assets/icons/MyTickets/repair.svg';
import finished from '@/assets/icons/MyTickets/finished.svg';
import tick from '@/assets/icons/MyTickets/tick.svg';
import fail from '@/assets/icons/MyTickets/fail.svg';
import clock from '@/assets/icons/MyTickets/clock.svg';
import pt from '@/plain-text';
import Taro from '@tarojs/taro';
import { FixStatus } from '@/common';

export class TicketListItem {
  id: number;
  brand: string;
  model: string;
  status: FixStatus;
  createAt: moment.Moment;
  iconMap: Map<FixStatus, string>;

  constructor(
    id: number,
    brand: string,
    model: string,
    status: FixStatus,
    createAt: moment.Moment,
  ) {
    this.id = id;
    this.brand = brand;
    this.model = model;
    this.status = status;
    this.createAt = createAt;
    this.iconMap = new Map<FixStatus, string>([
      [0, repair],
      [1, repair],
      [2, clock],
      [3, finished],
      [4, clock],
      [5, tick],
      [6, clock],
      [7, fail],
    ]);
  }

  render(): JSX.Element {
    const tl = pt.get().ticketList;
    return (
      <AtListItem
        title={this.brand + ' ' + this.model}
        note={tl.createdAt(this.createAt.format('YYYY-MM-DD HH:mm'))}
        extraText={tl.statusMap.get(this.status)}
        arrow='right'
        thumb={this.iconMap.get(this.status)}
        onClick={() => {
          Taro.navigateTo({
            url: '/pages/TicketDetail/TicketDetail?id=' + this.id,
          });
        }}
      />
    );
  }
}
