import * as React from "react";
import { Col, Form } from "react-bootstrap";

const SelectDoc = ({ setDocType, setDocTitle, doctype }: any) => {
  /** Different arrays for different dropdowns */
  const idProof = ["Aadhaar Card", "PAN Card", "Voter ID Card", "Passport"];
  const education = ["10th Marksheet", "10+2/Diploma Marksheet", "Graduation", "PG", "PGDM", "PHD"];
  const work = [
    "Resignation Letter",
    "Experience Letter",
    "Salary Slip(3 Month )",
    "Resume",
  ];
  const addressProof = ["Voter ID", "Aadhaar Card", "Residential Certificate"];
  /** Type variable to store different array for different dropdown */
  let type = null;

  /** This will be used to create set of options that user will see */
  let options = null;

  /** Setting Type variable according to dropdown */
  if (doctype === "KYC Document") {
    type = idProof;
  } else if (doctype === "Education") {
    type = education;
  } else if (doctype === "Work") {
    type = work;
  } else if (doctype === "Address Proof") {
    type = addressProof;
  }

  /** If "Type" is null or undefined then options will be null,
   * otherwise it will create a options iterable based on our array
   */
  if (type) {
    options = type.map((el) => <option key={el}>{el}</option>);
  }
  return (
    <>
      <Form.Group className="mb-3" as={Col} controlId="formGridDocType">
        <Form.Label>Document Type</Form.Label>
        <Form.Select
          name="doc_type"
          onChange={(e) => setDocType(e.target.value)}
        >
          <option>Select Document Type</option>
          <option value="KYC Document">KYC Document</option>
          <option value="Education">Education</option>
          <option value="Work">Work</option>
          <option value="Address Proof">Address Proof</option>
        </Form.Select>
      </Form.Group>
      <Form.Group className="mb-3" as={Col} controlId="formGridDocTitle">
        <Form.Label>Document Title</Form.Label>
        <Form.Select
          name="doc_title"
          onChange={(e) => setDocTitle(e.target.value)}
        >
          <option>Select Document Title</option>
          {
            /** This is where we have used our options variable */
            options
          }
        </Form.Select>
      </Form.Group>
    </>
  );
};

export default SelectDoc;
