import React, {useLayoutEffect} from "react";
import {randId} from "../../Helpers/random";
import iro from "@jaames/iro";

function BrightnessSlider({brightness, onChange}) {
  const random = randId();

  useLayoutEffect(() => {
    console.log(brightness);
    const colorPicker = new iro.ColorPicker("#color-picker-" + random, {
      color: `rgb(${brightness}, ${brightness}, ${brightness})`,
      layout: [
        {
          component: iro.ui.Slider,
          options: {
            borderColor: '#888'
          }
        }
      ],
    });

    colorPicker.on("input:end", color => {
      onChange(color.rgb.r);
    })
  }, []);

  return (
    <div id={`color-picker-${random}`}>

    </div>
  );
}

export default BrightnessSlider;
