import { useState } from "react";
import Button from "../../pageElements/Button";
import Modal from "react-bootstrap/Modal";
import TextInput from "../../pageElements/TextInput";
import { ExclamationTriangle } from "react-bootstrap-icons";
import { db } from "../../firebase";

const ConfirmModal = ({
  onCancel,
  onConfirm,
  buttonLabelText,
  modalText,
  isBusy,
  isReport,
  appUserId,
  caseId,
  documentId,
  issueText,
  setIssueText,
  reportDoc,
  titleText,
  isPromoModal,
  cancelButtonText,
}) => {
  const [inputValue, setInputValue] = useState("");
  const [codeError, setCodeError] = useState("");
  const title = titleText ? titleText : "Confirmation";
  const handleConfirm = (code) => {
    if (!code) {
      setCodeError("Please enter a code");
      return;
    }
    onConfirm(code);
  };
  return (
    <Modal show="true" onHide={onCancel} size="lg">
      <Modal.Header closeButton>
        {isReport ? (
          <Modal.Title>Report an issue</Modal.Title>
        ) : (
          <Modal.Title>
            {titleText && !isPromoModal ? (
              <ExclamationTriangle
                style={{
                  color: "red",
                  marginRight: "8px",
                  marginBottom: "6px",
                }}
              />
            ) : (
              <></>
            )}
            {title}
          </Modal.Title>
        )}
      </Modal.Header>
      <Modal.Body>
        <span>{modalText}</span>
        {isReport || isPromoModal ? (
          <div style={{ marginTop: "16px" }}>
            <TextInput
              key={"captionTwo"}
              name={"captionTwo"}
              value={inputValue}
              message={"data.captionTwo.message"}
              onChange={(e) => setInputValue(e.target.value)}
              label={
                inputValue
                  ? ""
                  : isPromoModal
                  ? "Paste or type your code"
                  : "Description of issue"
              }
            />
            <div className="confirm-error-box">
              {codeError ? (
                <p className="confirm-error-text">{codeError}</p>
              ) : (
                <></>
              )}
            </div>
          </div>
        ) : (
          <></>
        )}
      </Modal.Body>
      <Modal.Footer>
        <Button
          disabled={isBusy}
          className="secondary-button"
          onClick={onCancel}
          labelText={cancelButtonText ? cancelButtonText : "Cancel"}
        />
        <Button
          disabled={isBusy}
          className="primary-button"
          onClick={() => handleConfirm(inputValue)}
          labelText={buttonLabelText}
        />
      </Modal.Footer>
    </Modal>
  );
};

export default ConfirmModal;
