import { Injectable } from '@angular/core';
import {IGradientstop } from '../models/gradient'

@Injectable({
  providedIn: 'root',
})
export class GradientService {
  constructor() {
  }

  getGradientStyle(gradient:IGradientstop[],portrait = false ):any {
      let gd = '{ "background": "linear-gradient(to ' + (portrait?'bottom':'right') +',';
      for(let i=0;i<gradient.length;i++) {
        const gs = gradient[i];
        if(i>0) gd+=",";
        gd += `rgba(${gs.color.red},${gs.color.green},${gs.color.blue},${gs.color.alpha/255})`;          
        gd +=` ${gs.relativestop*100}%`
      }
      gradient.forEach((gs) => {
      });
      gd+=')"}';
      
      return JSON.parse(gd);
    }  
}
