"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _react = _interopRequireDefault(require("react"));

require("./index.less");

var _reactSlick = _interopRequireDefault(require("react-slick"));

var _mobx = require("../../../../../mobx");

var _AlignSelector = require("../../../../../common/AlignSelector");

require("slick-carousel/slick/slick.css");

require("slick-carousel/slick/slick-theme.css");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var __extends = void 0 && (void 0).__extends || function () {
  var _extendStatics = function extendStatics(d, b) {
    _extendStatics = Object.setPrototypeOf || {
      __proto__: []
    } instanceof Array && function (d, b) {
      d.__proto__ = b;
    } || function (d, b) {
      for (var p in b) {
        if (b.hasOwnProperty(p)) d[p] = b[p];
      }
    };

    return _extendStatics(d, b);
  };

  return function (d, b) {
    _extendStatics(d, b);

    function __() {
      this.constructor = d;
    }

    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  };
}();

var CarouselPc =
/** @class */
function (_super) {
  __extends(CarouselPc, _super);

  function CarouselPc() {
    var _this = _super !== null && _super.apply(this, arguments) || this;

    _this.state = {
      carouseIndex: 0,
      hoverState: false,
      clickedGroup: ''
    };
    _this.carouselRef = /*#__PURE__*/_react["default"].createRef();
    _this.destroy = null;

    _this.bannerGoto = function (groupSource) {
      var nextIndex = groupSource.findIndex(function (item) {
        return item.id === _mobx.store.clickedGroup;
      });

      if (nextIndex != -1 && nextIndex != _this.state.carouseIndex) {
        _this.carouselRef.current.goTo(nextIndex);
      }
    };

    _this.getItemStyle = function (item) {
      var data = _this.props.data;
      return {
        justifyContent: _AlignSelector.alignItemMap[item.customize.layout],
        height: data.setting.mobileHeight
      };
    };

    _this.mouseEnterWrap = function () {
      _this.setState({
        hoverState: true
      });
    };

    _this.mouseLeaveWrap = function () {
      _this.setState({
        hoverState: false
      });
    };

    return _this;
  }

  CarouselPc.prototype.componentDidMount = function () {
    var _this = this;

    this.destroy = (0, _mobx.autorun)(function () {
      _this.bannerGoto(_this.props.data.groupSource);
    });
  };

  CarouselPc.prototype.componentWillReceiveProps = function (nextProps) {
    this.bannerGoto(nextProps.data.groupSource);
  };

  CarouselPc.prototype.componentWillUnmount = function () {
    this.destroy();
  };

  CarouselPc.prototype.render = function () {
    var _settings;

    var data = this.props.data;
    console.log('data', data);
    var settings = (_settings = {
      // arrows: true,
      className: 'center',
      centerMode: true,
      infinite: true,
      centerPadding: '0rem',
      slidesToShow: 3,
      dots: true
    }, _defineProperty(_settings, "infinite", true), _defineProperty(_settings, "autoplay", true), _defineProperty(_settings, "speed", 500), _defineProperty(_settings, "slidesToShow", 1), _defineProperty(_settings, "slidesToScroll", 3), _settings);
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: "m-carousel-pc"
    }, /*#__PURE__*/_react["default"].createElement(_reactSlick["default"], settings, data.groupSource.map(function (item) {
      return /*#__PURE__*/_react["default"].createElement("div", {
        key: item.id,
        className: "img-wrap"
      }, /*#__PURE__*/_react["default"].createElement("img", {
        alt: "",
        src: item.image.content.imgSrc
      }));
    })));
  };

  CarouselPc.defaultProps = {
    data: {
      setting: {},
      groupSource: []
    }
  };
  return CarouselPc;
}(_react["default"].Component);

var _default = CarouselPc;
exports["default"] = _default;