"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Slider = void 0;
var react_1 = __importStar(require("react"));
var useEventListener_1 = require("@devesharp/react-hooks/lib/useEventListener");
var faChevronLeft_1 = require("@fortawesome/free-solid-svg-icons/faChevronLeft");
var faChevronRight_1 = require("@fortawesome/free-solid-svg-icons/faChevronRight");
var react_fontawesome_1 = require("@fortawesome/react-fontawesome");
var S = __importStar(require("./Slider.style"));
var Slider = function Slider(_a) {
    var items = _a.items, _b = _a.height, height = _b === void 0 ? 300 : _b, _c = _a.width, width = _c === void 0 ? '100%' : _c, _d = _a.boxCountPos, boxCountPos = _d === void 0 ? 'top-left' : _d, _e = _a.showBoxCount, showBoxCount = _e === void 0 ? true : _e, onChangeSlide = _a.onChangeSlide, _f = _a.arrowSize, arrowSize = _f === void 0 ? 50 : _f, onClickImage = _a.onClickImage, onRequestClose = _a.onRequestClose, _g = _a.bgColor, bgColor = _g === void 0 ? '#222' : _g, _slidePos = _a.slidePos;
    var _h = (0, react_1.useState)(0), slidePos = _h[0], setSlidePos = _h[1];
    (0, react_1.useLayoutEffect)(function () {
        if (_slidePos && _slidePos >= 0) {
            setSlidePos(_slidePos);
        }
    }, [_slidePos]);
    function nextSlide() {
        if (slidePos + 1 >= items.length) {
            if (onChangeSlide)
                onChangeSlide(0);
            setSlidePos(0);
        }
        else {
            if (onChangeSlide)
                onChangeSlide(slidePos + 1);
            setSlidePos(slidePos + 1);
        }
    }
    function previousSlide() {
        if (slidePos - 1 < 0) {
            if (onChangeSlide)
                onChangeSlide(items.length - 1);
            setSlidePos(items.length - 1);
        }
        else {
            if (onChangeSlide)
                onChangeSlide(slidePos - 1);
            setSlidePos(slidePos - 1);
        }
    }
    (0, useEventListener_1.useEventListener)('keydown.esc', function () {
        if (onRequestClose)
            onRequestClose();
    });
    (0, useEventListener_1.useEventListener)('keydown.arrowleft', function () {
        previousSlide();
    });
    (0, useEventListener_1.useEventListener)('keydown.arrowright', function () {
        nextSlide();
    });
    return (react_1.default.createElement(S.Container, { bgColor: bgColor, arrowSize: arrowSize, height: typeof height === 'string' ? height : "".concat(height, "px"), width: typeof width === 'string' ? width : "".concat(width, "px"), boxCountPos: boxCountPos },
        showBoxCount && (react_1.default.createElement("div", { className: "image-count", onClick: function () { return onClickImage && onClickImage(); } },
            react_1.default.createElement("span", null, slidePos + 1),
            " de ",
            react_1.default.createElement("span", null, items.length))),
        react_1.default.createElement("div", { className: "arrow left", onClick: previousSlide, "data-testid": "slider-btn-left" },
            react_1.default.createElement(react_fontawesome_1.FontAwesomeIcon, { icon: faChevronLeft_1.faChevronLeft })),
        react_1.default.createElement("div", { className: "arrow right", onClick: nextSlide, "data-testid": "slider-btn-right" },
            react_1.default.createElement(react_fontawesome_1.FontAwesomeIcon, { icon: faChevronRight_1.faChevronRight })),
        react_1.default.createElement("div", { className: "main" },
            react_1.default.createElement("ul", { className: "full-screen-slider", style: { transform: "translateX(-".concat(slidePos * 100, "%)") } }, !!items &&
                items.map(function (Image, index) { return (react_1.default.createElement("li", { key: "image-slide-".concat(index) },
                    !!(Image === null || Image === void 0 ? void 0 : Image.image) && (react_1.default.createElement(react_1.default.Fragment, null,
                        react_1.default.createElement("div", { className: "overlay", onClick: function () { return onRequestClose && onRequestClose(); }, "data-testid": "slider-background-".concat(index) }),
                        react_1.default.createElement("img", { src: Image.image, className: "rot".concat(Image.rotate), alt: "", onClick: function () { return onClickImage && onClickImage(); } }))),
                    !(Image === null || Image === void 0 ? void 0 : Image.image) && typeof Image === 'function' && react_1.default.createElement(Image, null),
                    !(Image === null || Image === void 0 ? void 0 : Image.image) && typeof Image !== 'function' && Image)); })))));
};
exports.Slider = Slider;
//# sourceMappingURL=Slider.js.map