import React from "react";
import useCameraStore from "../hooks/useCameraStore";
import { IconButton } from "@mui/material";
import { LocalShipping } from "@mui/icons-material";

const DispatchCamera: React.FC = () => {
  const { setImageDispatch } = useCameraStore();
  const handleCapture = (event: React.ChangeEvent<HTMLInputElement>) => {
    const file = event.target.files?.[0];
    if (file) {
      const reader = new FileReader();
      reader.onloadend = () => {
        setImageDispatch(reader.result as string);
      };
      reader.readAsDataURL(file);
    }
  };

  return (
    <div className="px-4 py-8 items-center border-2 rounded-md shadow-sm w-[49%] text-center ">
      <input
        type="file"
        accept="image/*"
        onChange={handleCapture}
        className="hidden"
        id="dispatchCameraInput"
      />
      <label htmlFor="dispatchCameraInput" className="text-gray-600">
        <IconButton
          color="primary"
          aria-label="upload picture"
          component="span"
        >
          <LocalShipping fontSize="large" />
        </IconButton>
        <br />
        Foto Dispatch
      </label>
    </div>
  );
};

export default DispatchCamera;
