import * as React from "react";
import { Col, Form } from "react-bootstrap";

const SelectLeaveComp = ({ setLeave, setLeaveShift, leavetypes, gender, creditLeaves, empLeaves }: any) => {
  /** Different arrays for different dropdowns */
  const idFull = ["Full Day"];
  const halfday = ["Half Day(Shift 1)", "Half Day(Shift 2)","Full Day"];
  /** 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 (leavetypes === "Maternity") {
    type = idFull;
  } else if (leavetypes === "Peternity") {
    type = idFull;
  } else if (leavetypes === "Marriage") {
    type = idFull;
  } else if (leavetypes === "Work From Home") {
    type = idFull;
  } else if (leavetypes === "Casual") {
    type = halfday;
  } else if (leavetypes === "Sick") {
    type = halfday;
  }

  /** 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">
                <Form.Control  type="hidden"
                  defaultValue={gender}
                  disabled={true}

                />
                 
              </Form.Group>
              <Form.Group as={Col} sm={12} md={12} lg={3} className="mb-3">
                <Form.Label>Leave Type</Form.Label>
                <Form.Select
                  name="leavetype"
                  defaultValue=""
                  onChange={setLeave}
                >
                  <option>Choose...</option>
                  {
                    creditLeaves && creditLeaves[0]?.casual_leave===parseInt(empLeaves[0]?.casual)?"":<option value="Casual">Casual</option>
                  }
                     {
                    creditLeaves && creditLeaves[0]?.sick_leave===parseInt(empLeaves[0]?.sick)?"":<option value="Sick" >Sick</option>
                  }
                  {
                    gender==="Male"?<option value="Peternity">Peternity</option>:<option value="Maternity">Maternity</option>
                  }
                  <option value="Marriage">Marriage</option>
                  <option value="Work From Home">Work From Home</option>
                </Form.Select>
              </Form.Group>
              <Form.Group as={Col} sm={12} md={12} lg={3} className="mb-3">
                <Form.Label>Leave Shift</Form.Label>
                <Form.Select
                  name="leave_shift"
                  defaultValue=""
                  onChange={(e:any)=>setLeaveShift(e.target.value)}
                >
                  <option>Choose...</option>
                {
                    /** This is where we have used our options variable */
                    options
                }
                  </Form.Select>
                </Form.Group>
    </>
  );
};

export default SelectLeaveComp;
