/**
 * Style for ApPassword.
 * @class ApPasswordStyle
 */

'use strict'

import React, {PropTypes as types} from 'react'
import {ApStyle} from 'apeman-react-style'

/** @lends ApPasswordStyle */
const ApPasswordStyle = React.createClass({
  propTypes: {
    style: types.object,
    highlightColor: types.string,
    maxWidth: types.number
  },
  getDefaultProps () {
    return {
      style: {},
      maxWidth: ApStyle.CONTENT_WIDTH,
      highlightColor: ApStyle.DEFAULT_HIGHLIGHT_COLOR
    }
  },
  statics: {
    styleData (config) {
      let { highlightColor, maxWidth } = config

      return {
        all: {
          '.ap-password': {
            display: 'block',
            padding: '4px 8px',
            border: '1px solid #AAA',
            width: '100%',
            maxWidth: `${maxWidth}px`,
            borderRadius: '2px',
            boxSizing: 'border-box',
            outlineColor: `${highlightColor}`,
            boxShadow: '1px 1px 1px rgba(0,0,0,.05) inset'
          },
          '.ap-password-wrap': {
            position: 'relative',
            width: '100%',
            margin: '4px',
            verticalAlign: 'middle',
            maxWidth: `${maxWidth}px`,
            display: 'block'
          },
          '.ap-password-wrap-empty .ap-password-toggle-button': {
            opacity: 0,
            pointerEvents: 'none'
          },
          '.ap-password-toggle-button': {
            position: 'absolute',
            top: 0,
            right: -4,
            display: 'inline-flex',
            alignItems: 'center',
            padding: '0 8px',
            bottom: 0,
            cursor: 'pointer',
            opacity: 0.8,
            transition: 'opacity 200ms'
          },
          '.ap-password-toggle-button:hover': {
            opacity: 1
          },
          '.ap-password-toggle-button:active': {
            opacity: 0.9
          },
          '.ap-password-toggle-aligner': {
            display: 'inline-block',
            verticalAlign: 'middle',
            width: '1px',
            marginRight: '-1px',
            height: '100%',
            boxSizing: 'border-box',
            opacity: 0
          },
          '.ap-password-toggle-icon': {
            display: 'inline-block',
            verticalAlign: 'middle'
          }
        }
      }
    }
  },
  render () {
    const s = this
    let { props } = s

    let { all, small, medium, large } = ApPasswordStyle.styleData(props)

    return (
      <ApStyle data={ Object.assign(all, props.style) }
               smallMediaData={ small }
               mediumMediaData={ medium }
               largeMediaData={ large }
      >{ props.children }</ApStyle>
    )
  }
})

export default ApPasswordStyle
