import { Input, Label } from '@bjsdistribution/dms-component-library';
import React from 'react';
import styled from 'styled-components';
import { useOrderDetails } from '../../../store';
import CopyText from '../../../../../common/copy/CopyText';

function RecipientReference() {
  const [orderDetails, setOrderDetails] = useOrderDetails();
  const orderRecipient = orderDetails?.recipient_reference;
  const showCopyIcon =
    orderRecipient !== undefined &&
    orderRecipient !== null &&
    orderRecipient?.length > 0;
  const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
    setOrderDetails(prev => {
      return {
        ...prev,
        recipient_reference: e.target.value,
      };
    });
  };
  return (
    <Container>
      <Wrapper>
        <Label label="Recipient Reference" htmlFor="recipient-reference" />
        {showCopyIcon && <CopyText text={orderRecipient!} />}
      </Wrapper>
      <Input
        name="recipient-reference"
        type="text"
        placeholder="Enter Recipient Reference"
        value={orderDetails.recipient_reference || ''}
        onChange={onChange}
        style={{ borderRadius: '25px' }}
      />
    </Container>
  );
}

const Container = styled.div`
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
`;

const Wrapper = styled.div`
  display: flex;
  align-items: center;
  gap: 5px;
`;

export default RecipientReference;
