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

function DeliveryInstructions() {
  const [orderDetails, setOrderDetails] = useOrderDetails();

  const onChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
    setOrderDetails(prev => {
      return {
        ...prev,
        delivery_instructions: e.target.value,
      };
    });
  };

  return (
    <Container>
      <Label label="Delivery Instructions" />
      <CustomTextArea
        value={orderDetails?.delivery_instructions || ''}
        placeholder="add delivery instructions"
        onChange={onChange}
      />
    </Container>
  );
}

const CustomTextArea = styled(TextArea)`
  flex: 1;
  resize: none;
`;

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

export default DeliveryInstructions;
