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

function OrderNumber() {
  const [orderDetails, setOrderDetails] = useOrderDetails();
  const showCopyIcon =
    orderDetails?.order_number !== null &&
    orderDetails?.order_number !== undefined &&
    orderDetails?.order_number?.length > 0;

  const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
    setOrderDetails(prev => {
      return {
        ...prev,
        order_number: e.target.value,
      };
    });
  };
  return (
    <Container>
      <Wrapper>
        <Label label="Order Number" htmlFor="order-number" />
        {showCopyIcon && <CopyText text={orderDetails?.order_number!} />}
      </Wrapper>
      <Input
        name="order-number"
        type="text"
        placeholder="Order Number"
        value={orderDetails?.order_number || ''}
        onChange={onChange}
        style={{ borderRadius: '25px' }}
      />
    </Container>
  );
}

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

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

export default OrderNumber;
