import React from 'react'
import styled from 'styled-components'
import { IJsonSchema } from '../../types/IJsonSchema'
import { InputWrapper } from '../InputWrapper/InputWrapper'

export type PasswordInputProps = {
  name: string
  placeholder?: string
  label?: string;
  /**
   * schema for validation
   */
  jsonSchema?: IJsonSchema
  value?: string 
  /**
   * custom styling for password input
   */
  css?: string
  onChange: (change: string) => void
}

export const PasswordInput = ({
  name,
  value,
  placeholder,
  jsonSchema,
  onChange,
  label,
  css,
}: PasswordInputProps):JSX.Element => {

  const handleChange = (event:React.ChangeEvent<HTMLInputElement>) => {
    onChange(event.target.value)
  }

  return (
    <InputWrapper label={label}
      jsonSchema={jsonSchema} 
      value={value}>
      <StyledPasswordInput
        type="password" 
        value={value}
        name={name}
        placeholder={placeholder}
        css={css}
        onChange={handleChange}
      />
    </InputWrapper>
  )
}

const StyledPasswordInput = styled.input<{css?:string}>`
  font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji;
  height: 36px;
  -webkit-tap-highlight-color: transparent;
  line-height: 34px;
  resize: none;
  box-sizing: border-box;
    font-size: 1rem;
  color: #000;
  width:100%;
  text-align: left;
  min-height: 36px;
  padding-left: 5px;
  padding-right: 12px;
  border-radius: 4px;
  border: none;
  background-color: #fff;
  -webkit-transition: border-color 100ms ease;
  transition: border-color 100ms ease;
  
  &:focus {
    outline: none;
    border-color: #228be6;
   }

  ${(p) => p.css}
`

