import { FC } from 'react'
import styled from 'styled-components'

import { colors, levelColors } from '../style-vars'
import { LevelItem } from './common'
import addDocIcon from '../assets/medical-clipboard.svg'
import { FreshMark } from './FreshMark'

interface ZoomInCustomerItemProps {
  data: LevelItem
  onTrackOpen: (url: string, rid: string) => void
}

const ZoomInCustomerItemWrapper = styled.div<{ avail: boolean }>`
  flex-shrink: 0;
  width: 100%;
  box-sizing: border-box;
  height: 54px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  background-color: rgba(255, 255, 255, 0.42);
  box-shadow: 0 2px 8px 1px rgb(0 0 0 / 5%);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 3px;
  padding: 0 16px;
  cursor: pointer;
  transition: all 0.2s ease-in;
  &:last-child {
    margin-bottom: 0;
  }
  .infos {
    display: flex;
    align-items: center;

    .tagContainer {
      display: flex;
      justify-content: flex-end;
      margin-left: 8px;
    }
  }

  &:hover {
    background-color: rgba(255, 255, 255, 1);
  }
`

const Title = styled.div`
  flex-grow: 1;
  min-width: 100px;
  display: flex;
  margin-right: 12px;
  align-items: center;
  width: 0;
  height: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  font-size: 16px;
  color: ${colors.fgMain};
`

const AddDocIcon = styled.img`
  display: flex;
  align-items: center;
  margin-left: 12px;
  height: 14px;
  opacity: 0.4;
`

// const CustomerTag = styled.div`
//   display: flex;
//   margin-left: 8px;
//   align-items: center;
//   height: 22px;
//   border-radius: 2px;
//   padding: 0 6px;
//   font-size: 12px;
//   font-weight: 600;
//   background-color: ${colors.white};
//   color: ${colors.fgMain};
//   white-space: nowrap;
// `

const BusinessTag = styled.div<{ l: number }>`
  display: flex;
  margin-left: 8px;
  align-items: center;
  height: 22px;
  border-radius: 2px;
  padding: 0 6px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background-color: ${({ l }) =>
    l === 0 ? colors.fgSecondary : levelColors[`l${l}`][levelColors[`l${l}`].length - 1]};
  color: ${colors.white};
`

export const ZoomInCustomerItem: FC<ZoomInCustomerItemProps> = ({ data, onTrackOpen }) => {
  return (
    <ZoomInCustomerItemWrapper
      onClick={() => onTrackOpen(data.bhr || '', data.rid || '')}
      avail={!!data.bhr}
    >
      {!!data.curStaySec && (
        <FreshMark
          deltSec={data.curStaySec}
          name={data.name}
          pm={data.pm}
          firstPMLarkLink={data.firstPMLarkLink}
        />
      )}
      <Title>{data.name}</Title>
      <div className="infos">
        {/* {data.ct ? (
          <div className="tagContainer">
            {data.ct.split(',').map((ct) => (
              <CustomerTag key={ct}>{ct.trim()}</CustomerTag>
            ))}
          </div>
        ) : null} */}
        {data.bt ? (
          <div className="tagContainer">
            {data.bt.split(',').map((bt) => (
              <BusinessTag key={bt} l={!data.level ? 0 : Number(data.level)}>
                {bt.trim()}
              </BusinessTag>
            ))}
          </div>
        ) : null}
      </div>
      {!data.bhr && <AddDocIcon src={addDocIcon} />}
    </ZoomInCustomerItemWrapper>
  )
}
