function replacePx(val) {
  return +(val || '').replace('px', '');
}

function getStyle(componentData) {
  const styles = [];

  const {
    componentExtInfo,
  } = componentData;

  const { height } = componentExtInfo || {};

  styles.push(`height:${(replacePx(height) || 130) / 50}rem`);

  return styles.join(';');
}

function getServiceList(componentData) {
  const {
    serviceList = [],
  } = componentData || {};
  return serviceList;
}

function hasService(componentData) {
  return !!getServiceList(componentData).length;
}

function getInterval(componentData, interval) {
  const {
    componentExtInfo,
  } = componentData;
  const {
    advertRate = 0,
  } = componentExtInfo || {};
  return (+advertRate || interval) * 1000;
}

function getFullUrl(url, prefix) {
  return url.length === 32 ? `${prefix}${url}` : url;
}

export default {
  getFullUrl,
  getStyle,
  hasService,
  getInterval,
  getServiceList,
};
