<?php
namespace App\Controller;

use App\Definition\Controller;
use App\Helper\Color;
use App\Helper\Line;
use Incoviba\common\Registry as RModel;

class Registros
{
  use Controller;
  public static function list()
  {
    $registros = model(RModel::class)->orderByDesc('time')->findMany();
    $ini = new Color(0, 100, 0);
    $end = new Color(255, 255, 255);
    $colores = self::colores($end, $ini, 100);
    return view('admin.registros.list', compact('registros', 'colores'));
  }
  public static function show()
  {
    $registro = model(RModel::class)->findOne(get('registro'));
    $ini = new Color(0, 100, 0);
    $end = new Color(255, 255, 255);
    $colores = self::colores($end, $ini, 100);
    return view('admin.registros.show', compact('registro', 'colores'));
  }
  protected static function colores($ini, $end, $max)
  {
    $current = $ini->toVector();
    $colores = [];
    $line = new Line($ini->toVector(), $end->toVector());
    for ($i = 0; $i < $max; $i ++) {
      $colores[$i] = new Color($current);
      $current = $line->move($current, $line->length() / $max);
    }
    return $colores;
  }
}
