'use strict';
const platform = (navigator && navigator.platform) || '';
const ua = (navigator && navigator.userAgent) || '';
const REG_MAC = /mac/i;
const REG_WIN = /win/i;
const REG_ALIAPP = /AliApp\(.+\)/;
const REG_IOS = /[iPhone|iPad]/;
const REG_ANDROID = /android/i;
let stickyStyle = {
  position: 'sticky',
  top: 0,
  zIndex: 999
};
if (
  (REG_ALIAPP.test(ua) || REG_IOS.test(ua)) &&
  !REG_ANDROID.test(ua) &&
  !REG_MAC.test(platform) &&
  !REG_WIN.test(platform)
) {
  stickyStyle.position = '-webkit-sticky';
}

export default function(Wrapped: any) {
  const defaultProps = Wrapped.defaultProps || {};
  const style = defaultProps.style || {};
  Wrapped.defaultProps = {
    ...defaultProps,
    style: {
      ...style,
      ...stickyStyle
    }
  };
  return Wrapped;
}
