{"size": 1053, "ext": "js", "max_stars_repo_path": "lib/components/Link/Link.js", "max_stars_repo_name": "9dots/artbot", "max_stars_repo_stars_event_min_datetime": "2017-03-14T17:42:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-16T21:22:19.000Z", "max_issues_repo_path": "lib/components/Link/Link.js", "max_issues_repo_name": "9dots/artbot", "max_issues_repo_issues_event_min_datetime": "2017-02-10T01:53:33.000Z", "max_issues_repo_issues_event_max_datetime": "2018-05-31T18:31:48.000Z", "max_forks_repo_path": "lib/components/Link/Link.js", "max_forks_repo_name": "9dots/artbot", "max_forks_repo_forks_event_min_datetime": "2017-04-28T18:56:22.000Z", "max_forks_repo_forks_event_max_datetime": "2017-10-06T19:02:40.000Z"}
{"max_stars_count": 19, "max_issues_count": 412, "max_forks_count": 2, "avg_line_length": 19.1454545455, "max_line_length": 136, "alphanum_fraction": 0.5735992403}
/**
 * Imports
 */

import {preventDefault, component, element} from 'vdux'
import {CSSContainer} from 'vdux-containers'
import {Base} from 'vdux-ui'

/**
 * <Link/>
 */

export default component({
  render ({props, children, context}) {
    const {ui = InternalLink, current = isCurrent(props.href, context.url), href, disabled, replace, currentProps = {}, ...rest} = props
    let onClick = props.onClick

    if ((ui !== InternalLink && href && !disabled) || replace) {
      onClick = [context.setUrl(href, replace), preventDefault]
    }

    return (
      <CSSContainer
        ui={ui}
        {...rest}
        disabled={disabled}
        href={href}
        onClick={onClick}
        {...(current ? currentProps : {})}>
        {children}
      </CSSContainer>
    )
  }
})

/**
 * <InternalLink/>
 */

function InternalLink ({props, children}) {
  return (
    <Base tag='a' {...props}>
      {children}
    </Base>
  )
}

/**
 * Helpers
 */

function isCurrent (href = '', currentUrl = '') {
  return href && currentUrl.indexOf(href) === 0
}
