(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "tslib", "react", "../../../utils/colorConvectors/hsvToHex", "./helpers/calculateChange", "./styles"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var tslib_1 = require("tslib");
    var react_1 = (0, tslib_1.__importStar)(require("react"));
    var hsvToHex_1 = require("../../../utils/colorConvectors/hsvToHex");
    var calculateChange_1 = require("./helpers/calculateChange");
    var styles_1 = require("./styles");
    var Hue = function (_a) {
        var hsl = _a.hsl, hsv = _a.hsv, setHsl = _a.setHsl, setHsv = _a.setHsv, setColorInput = _a.setColorInput;
        var container = (0, react_1.useRef)(null);
        (0, react_1.useEffect)(function () { return function () { return unbindEventListeners(); }; }, []);
        var handleChange = function (e) {
            if (container.current) {
                var change = (0, calculateChange_1.calculateChange)(e, hsl, container.current);
                setHsl(change);
                var newHSV = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, hsv), { h: change.h });
                setHsv(newHSV);
                setColorInput((0, hsvToHex_1.hsvToHex)(newHSV).toUpperCase());
            }
        };
        var handleMouseDown = function (e) {
            handleChange(e);
            window.addEventListener("mousemove", handleChange);
            window.addEventListener("mouseup", handleMouseUp);
        };
        var handleMouseUp = function () {
            unbindEventListeners();
        };
        var unbindEventListeners = function () {
            window.removeEventListener("mousemove", handleChange);
            window.removeEventListener("mouseup", handleMouseUp);
        };
        return (react_1.default.createElement(styles_1.ColorLine, { ref: container },
            react_1.default.createElement(styles_1.PointButton, { onMouseDown: handleMouseDown, hue: hsl.h, left: Math.round(hsl.h) * 100 })));
    };
    exports.default = Hue;
});
