import IPoint from '@/models/IPoint'
import { money } from '@/utils/filters'
import ICurrency from '@/models/ICurrency'

class ChartService {
  public valueToPoint(value: number, index: number, total: number): IPoint {
    const x = 0
    const y = -value * 1.6
    const angle = ((Math.PI * 2) / total) * index
    const cos = Math.cos(angle)
    const sin = Math.sin(angle)
    const tx = x * cos - y * sin + 200
    const ty = x * sin + y * cos + 200
    return {
      x: tx,
      y: ty
    }
  }

  public getLabel(user: string, cost: number, currency: ICurrency): string {
    if (!user) {
      return ''
    }
    return `${user} (${money(cost, currency)})`
  }
}

export default new ChartService()
