var _excluded = ["width"],
    _excluded2 = ["width"];

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

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; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

/*
 * @Author: codingfly
 * @Description:
 * @Date: 2021-11-22 08:28:19
 * @LastEditTime: 2022-06-14 13:41:40
 * @FilePath: \remaxui\src\notice-bar\index.tsx
 */
import React from 'react';
import { View } from 'remax/one';
import classNames from 'classnames';
import styles from './index.module.less';
import useViewLayout from '../use-view-layout';
import Space from '../space';
import Icon from '../icon';

var NoticeBar = function NoticeBar(props) {
  var _classNames;

  var className = props.className,
      style = props.style,
      _props$background = props.background,
      background = _props$background === void 0 ? '#fefcec' : _props$background,
      _props$color = props.color,
      color = _props$color === void 0 ? '#FF9D46' : _props$color,
      _props$icon = props.icon,
      icon = _props$icon === void 0 ? /*#__PURE__*/React.createElement(Icon, {
    name: "notice",
    size: '18px'
  }) : _props$icon,
      _props$speed = props.speed,
      speed = _props$speed === void 0 ? 0 : _props$speed,
      title = props.title,
      closeable = props.closeable,
      onClose = props.onClose,
      children = props.children;

  var _useViewLayout = useViewLayout(),
      _useViewLayout$width = _useViewLayout.width,
      innerW = _useViewLayout$width === void 0 ? 0 : _useViewLayout$width,
      arg1 = _objectWithoutProperties(_useViewLayout, _excluded);

  var _useViewLayout2 = useViewLayout(),
      _useViewLayout2$width = _useViewLayout2.width,
      contentW = _useViewLayout2$width === void 0 ? 999 : _useViewLayout2$width,
      arg2 = _objectWithoutProperties(_useViewLayout2, _excluded2);

  var new_style = function new_style() {
    if (speed !== 0) {
      return {
        animationDuration: "".concat(speed, "s"),
        paddingLeft: contentW + 'PX'
      };
    }
  };

  return /*#__PURE__*/React.createElement(View, {
    className: classNames(styles.noticeBarBox, className),
    style: _objectSpread({
      background: background,
      color: color
    }, style)
  }, /*#__PURE__*/React.isValidElement(icon) && /*#__PURE__*/React.cloneElement(icon, {
    color: color
  }), title && /*#__PURE__*/React.createElement(View, {
    className: styles.noticeBarTitle
  }, title, "\uFF1A"), /*#__PURE__*/React.createElement(View, _objectSpread(_objectSpread({}, arg2), {}, {
    className: classNames((_classNames = {}, _defineProperty(_classNames, styles.noticeContentAnimation, speed !== 0), _defineProperty(_classNames, styles.noticeContent, speed === 0), _classNames))
  }), /*#__PURE__*/React.createElement(View, _objectSpread(_objectSpread({}, arg1), {}, {
    className: classNames(_defineProperty({}, styles.noticeInner, speed !== 0)),
    style: new_style()
  }), /*#__PURE__*/React.createElement(Space, {
    size: 10,
    flexWrap: 'nowrap',
    alignItems: 'center'
  }, children))), closeable && /*#__PURE__*/React.createElement(View, {
    className: styles.right,
    onTap: function onTap() {
      onClose === null || onClose === void 0 ? void 0 : onClose();
    }
  }, /*#__PURE__*/React.createElement(Icon, {
    name: "clear2",
    color: color,
    size: '18px'
  })));
};

export default NoticeBar;