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

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

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

  return (
    <Container>
      <Label label="Droptime" htmlFor="droptime" />
      <CustomInput
        name="droptime"
        type="number"
        placeholder="0"
        onKeyDown={handleKeyDown}
        value={orderDetails?.drop_time || ''}
        onChange={onChange}
      />
    </Container>
  );
}

const CustomInput = styled(Input)`
  &::-webkit-outer-spin-button,
  &::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
  }
  &:focus-visible {
    outline: none;
  }
`;

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

export default Droptime;
