"use strict";

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

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

var _antd = require("antd");

var _indexModule = _interopRequireDefault(require("./index.module.less"));

var _coreUtil = require("../../../utils/coreUtil");

var _common = require("../../../common");

var _BaseConfig = _interopRequireDefault(require("../BaseConfig"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": 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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
      }
    };

    return _extendStatics(d, b);
  };

  return function (d, b) {
    if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");

    _extendStatics(d, b);

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

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

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

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

    _this.onClick = function (event) {
      console.log(event);
    };

    _this.getImg = function (v) {
      var data = _this.props.data;

      if ((0, _coreUtil.isPc)()) {
        data.content.pcImgSrc = v.url;
        data.content.pcName = v.contentTitle;

        if (!data.content.h5ImgSrc) {
          data.content.h5ImgSrc = v.url;
          data.content.h5Name = v.contentTitle;
        }
      } else {
        data.content.h5ImgSrc = v.url;
        data.content.h5Name = v.contentTitle;
      }

      _this.selfRender();
    };

    _this.getImgHoverUrl = function (v) {
      var data = _this.props.data;

      if ((0, _coreUtil.isPc)()) {
        data.hover.pcImgHoverUrl = v.url;

        if (!data.hover.h5ImgHoverUrl) {
          data.hover.h5ImgHoverUrl = v.url;
        }
      } else {
        data.hover.h5ImgHoverUrl = v.url;
      }

      _this.selfRender();
    };

    return _this;
  }

  ImageConfig.prototype.render = function () {
    var _this = this;

    var data = this.props.data;
    console.log('---image', this.props);

    var ContentSetting = /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_common.ImagePicker, {
      onChange: function onChange(v) {
        _this.getImg(v);
      },
      value: (0, _coreUtil.isPc)() ? data.content.pcImgSrc : data.content.h5ImgSrc
    }), /*#__PURE__*/_react["default"].createElement(_common.Field, {
      split: true,
      title: "URL"
    }, /*#__PURE__*/_react["default"].createElement(_common.UrlPicker, {
      onChange: function onChange(v) {
        data.content.clickUrl = v;

        _this.selfRender();
      },
      value: data.content.clickUrl
    })));

    var HoverSetting = /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_common.Field, {
      split: data.hover.backgroundType === 'new',
      title: "Image"
    }, /*#__PURE__*/_react["default"].createElement(_antd.Select, {
      className: _indexModule["default"].hoverSelect,
      onChange: function onChange(v) {
        data.hover.backgroundType = v;

        _this.selfRender();
      },
      size: "large",
      value: data.hover.backgroundType
    }, /*#__PURE__*/_react["default"].createElement(_antd.Select.Option, {
      value: "enlarge"
    }, "Enlarge"), /*#__PURE__*/_react["default"].createElement(_antd.Select.Option, {
      value: "new"
    }, "New image"))), data.hover.backgroundType === 'enlarge' && /*#__PURE__*/_react["default"].createElement(_common.Field, {
      title: "Magnification"
    }, /*#__PURE__*/_react["default"].createElement(_common.Slider, {
      inputType: "float",
      maxVal: 3,
      minVal: 1,
      onChange: function onChange(v) {
        data.hover.magnification = v.count;

        _this.selfRender();
      },
      step: 0.25,
      value: {
        count: data.hover.magnification
      }
    })), data.hover.backgroundType === 'new' && /*#__PURE__*/_react["default"].createElement(_common.ImagePicker, {
      onChange: function onChange(v) {
        return _this.getImgHoverUrl(v);
      },
      value: (0, _coreUtil.isPc)() ? data.hover.pcImgHoverUrl : data.hover.h5ImgHoverUrl
    }));

    return /*#__PURE__*/_react["default"].createElement("div", {
      className: _indexModule["default"].container,
      onClick: this.onClick
    }, /*#__PURE__*/_react["default"].createElement(_common.Collapse, {
      onRefresh: this.selfRender,
      source: [{
        key: '1',
        name: 'Content',
        value: ContentSetting
      }, {
        key: '5',
        name: 'Hover',
        value: HoverSetting,
        metaOption: data.hover,
        toggleType: 'checkbox'
      }]
    }));
  };

  ImageConfig.defaultProps = {
    data: {
      content: {
        clickUrl: '',
        pcImgSrc: '',
        h5ImgSrc: '',
        name: ''
      },
      hover: {
        open: false,
        backgroundType: 'enlarge',
        h5ImgHoverUrl: '',
        pcImgHoverUrl: '',
        magnification: 1
      }
    }
  };
  return ImageConfig;
}(_BaseConfig["default"]);

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