import EmailPreview from './EmailPreview.js';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { createContext, useState, useContext, createElement } from 'react';
import classnames from 'classnames';
import { useFormikContext, Field } from 'formik';
import { isPresent, isNotEmpty, notEqualsDeep, noop } from '@bigbinary/neeto-cist';
import FormikEditor from '@bigbinary/neeto-editor/FormikEditor';
import Typography from '@bigbinary/neetoui/Typography';
import Button from '@bigbinary/neetoui/Button';
import ActionBlock from '@bigbinary/neetoui/formik/ActionBlock';
import Radio from '@bigbinary/neetoui/formik/Radio';
import { prop, equals, pluck, isEmpty } from 'ramda';
import { useTranslation, Trans } from 'react-i18next';
import { t } from 'i18next';
import { isEditorEmpty } from '@bigbinary/neeto-editor/utils';
import * as yup from 'yup';
import Select from '@bigbinary/neetoui/formik/Select';
import Input from '@bigbinary/neetoui/formik/Input';
import _typeof from '@babel/runtime/helpers/typeof';
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
import SendToFields from './SendToFields.js';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import { withEventTargetValue } from '@bigbinary/neeto-commons-frontend/utils/general';
import Input$1 from '@bigbinary/neetoui/Input';
import DynamicVariables from './DynamicVariables.js';
import Tooltip from '@bigbinary/neetoui/Tooltip';
import BlockNavigation from '@bigbinary/neetoui/formik/BlockNavigation';
import Switch from '@bigbinary/neetoui/formik/Switch';
import Header from './Header.js';
import MobilePreviewHeader from './MobilePreviewHeader.js';
import { n } from './inject-css-C2dztUxs.js';
import Form from '@bigbinary/neetoui/formik/Form';
import '@bigbinary/neeto-commons-frontend/react-utils/withT';
import '@bigbinary/neeto-editor/EditorContent';
import './index-DAYCJu79.js';
import './_commonjsHelpers-BFTU3MAI.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@bigbinary/neeto-icons/Upload';
import '@bigbinary/neetoui/Toastr';
import '@bigbinary/neetoui/formik/MultiEmailInput';
import '@bigbinary/neetoui/Pane';
import 'react-dropzone';
import '@bigbinary/neeto-icons/Download';
import '@bigbinary/neetoui/Callout';
import 'stream';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@bigbinary/neeto-icons/Braces';
import '@bigbinary/neetoui/Dropdown';
import './Breadcrumbs.js';
import 'react-router-dom';
import './HelpPopover.js';
import '@bigbinary/neeto-icons/Help';
import '@bigbinary/neetoui/Popover';
import './MoreDropdown.js';
import '@bigbinary/neeto-icons/MenuHorizontal';
import '@bigbinary/neeto-icons/MenuVertical';
import '@bigbinary/neeto-commons-frontend/react-utils';
import './Search.js';
import '@bigbinary/neeto-commons-frontend/react-utils/useFuncDebounce';
import '@bigbinary/neeto-commons-frontend/react-utils/useQueryParams';
import '@bigbinary/neeto-commons-frontend/react-utils/useUpdateEffect';
import '@bigbinary/neeto-icons/Search';
import '@bigbinary/neeto-commons-frontend/utils';

var INITIAL_FORM_VALUES = {
  sendTo: [],
  sendToId: "",
  sendToCc: [],
  sendToBcc: [],
  replyTo: "",
  showCopyEmails: false,
  subject: "",
  message: "",
  isEnabled: false
};
var EMAIL_FORM_VALIDATION_SCHEMA = yup.object({
  subject: yup.string().required(t("neetoMolecules.emailForm.errors.subjectRequired")),
  message: yup.string().test("message", t("neetoMolecules.emailForm.errors.messageRequired"), function (value) {
    return !isEditorEmpty(value);
  })
});
var sendToFieldValidation = function sendToFieldValidation(maxEmails) {
  var validation = yup.array().test("all-emails-valid", t("neetoMolecules.emailForm.errors.invalidEmailAddress"), function (emails) {
    return emails === null || emails === void 0 ? void 0 : emails.every(prop("valid"));
  }).test("max-email-count", t("neetoMolecules.emailForm.errors.maxEmails", {
    count: maxEmails
  }), function (emails) {
    return (emails === null || emails === void 0 ? void 0 : emails.length) <= maxEmails;
  });
  return yup.object({
    sendTo: validation.min(1, t("neetoMolecules.emailForm.errors.required", {
      entity: t("neetoMolecules.emailForm.fields.sendToEmailAddress")
    })).nullable(),
    sendToCc: validation,
    sendToBcc: validation
  });
};
var SEND_TO_ID_FIELD_VALIDATION = yup.object({
  sendToId: yup.string().required(t("neetoMolecules.emailForm.errors.required", {
    entity: t("neetoMolecules.emailForm.labels.sendTo")
  }))
});
var REPLY_TO_FIELD_VALIDATION = yup.object({
  replyTo: yup.string().nullable().email(t("neetoMolecules.emailForm.errors.invalidEmailAddress")).required(t("neetoMolecules.emailForm.errors.required", {
    entity: t("neetoMolecules.emailForm.fields.replyToEmailAddress")
  }))
});
var EDITOR_ADDONS = ["highlight", "emoji", "code-block", "block-quote", "image-upload", "divider", "video-embed"];

/* eslint-disable @bigbinary/neeto/use-zustand-for-global-state-management */
var EmailFormContext = /*#__PURE__*/createContext({
  showSendToField: false,
  showSendToAsRadio: false,
  showReplyToField: false
});

function ownKeys$3(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$3(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$3(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var getValidationSchema = function getValidationSchema(_ref) {
  var showSendToField = _ref.showSendToField,
    showReplyToField = _ref.showReplyToField,
    showSendToAsRadio = _ref.showSendToAsRadio,
    customValidations = _ref.customValidations,
    maxEmails = _ref.maxEmails;
  var schema = EMAIL_FORM_VALIDATION_SCHEMA.clone();
  if (showSendToField) {
    schema = schema.concat(showSendToAsRadio ? SEND_TO_ID_FIELD_VALIDATION : sendToFieldValidation(maxEmails));
  }
  if (showReplyToField) schema = schema.concat(REPLY_TO_FIELD_VALIDATION);
  var isYupObject = customValidations.type === "object";
  if (isYupObject) {
    var customFields = customValidations.fields || {};
    schema = schema.shape(customFields);
  } else if (_typeof(customValidations) === "object") {
    schema = schema.shape(customValidations);
  }
  return schema;
};
var getReplyToFieldLabelProps = function getReplyToFieldLabelProps(_ref2) {
  var popoverProps = _ref2.popoverProps;
  return {
    helpIconProps: _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "data-testid", "reply-to-tooltip"), "data-cy", "reply-to-tooltip"), "tooltipProps", !isPresent(popoverProps) && {
      content: t("neetoMolecules.emailForm.tooltips.replyTo"),
      touch: ["hold", 500]
    }), "popoverProps", isPresent(popoverProps) && _objectSpread$3(_objectSpread$3({}, popoverProps), {}, {
      appendTo: "parent",
      description: popoverProps.description || t("neetoMolecules.emailForm.tooltips.replyTo")
    }))
  };
};
var resolveContent = function resolveContent(content, func, variable) {
  if (typeof func === "function") {
    return func(content, variable);
  }
  return content;
};
var normalizeHtmlString = function normalizeHtmlString(str) {
  if (typeof str !== "string") return str;
  return str.replace(/\uFEFF/g, "").replace(/\r\n|\r/g, "\n").replace(/&nbsp;/g, " ").replace(/[\t ]+/g, " ").replace(/\s*\n\s*/g, "\n").replace(/\n+/g, "\n").replace(/>\s+</g, "><").trim();
};

var ReplyToField = function ReplyToField(_ref) {
  var _ref$options = _ref.options,
    options = _ref$options === void 0 ? [] : _ref$options,
    _ref$popoverProps = _ref.popoverProps,
    popoverProps = _ref$popoverProps === void 0 ? {} : _ref$popoverProps;
  var _useTranslation = useTranslation(),
    t = _useTranslation.t;
  var _useFormikContext = useFormikContext(),
    setFieldValue = _useFormikContext.setFieldValue;
  var isDropdownField = isNotEmpty(options);
  var labelProps = getReplyToFieldLabelProps({
    popoverProps: popoverProps
  });
  if (isDropdownField) {
    return /*#__PURE__*/jsx(Select, {
      labelProps: labelProps,
      options: options,
      isClearable: true,
      className: "w-full",
      "data-testid": "replyToOptions",
      label: t("neetoMolecules.emailForm.labels.replyTo"),
      name: "replyTo",
      onChange: function onChange(data) {
        var _data$value;
        return setFieldValue("replyTo", (_data$value = data === null || data === void 0 ? void 0 : data.value) !== null && _data$value !== void 0 ? _data$value : "");
      }
    });
  }
  return /*#__PURE__*/jsx(Input, {
    labelProps: labelProps,
    autoFocus: true,
    required: true,
    className: "w-full",
    "data-testid": "replyToInput",
    label: t("neetoMolecules.emailForm.labels.replyTo"),
    name: "replyTo",
    placeholder: t("neetoMolecules.emailForm.placeholders.emailPlaceholder"),
    size: "large",
    onChange: function onChange(event) {
      var _event$target$value;
      return setFieldValue("replyTo", (_event$target$value = event.target.value) === null || _event$target$value === void 0 ? void 0 : _event$target$value.toLowerCase());
    }
  });
};

var SendToField = function SendToField(_ref) {
  var showBccField = _ref.showBccField,
    showCcField = _ref.showCcField,
    showSendToTextField = _ref.showSendToTextField;
  var _useTranslation = useTranslation(),
    t = _useTranslation.t;
  if (!showSendToTextField && !showBccField && !showCcField) return null;
  return /*#__PURE__*/jsx(SendToFields, {
    showCcBccButton: true,
    showBccField: showSendToTextField ? false : showBccField,
    showCcField: showSendToTextField ? false : showCcField,
    showSendToField: showSendToTextField,
    bccInputProps: {
      label: t("neetoMolecules.emailForm.labels.bCc"),
      name: "sendToBcc",
      placeholder: t("neetoMolecules.emailForm.placeholders.commaSeparatedEmails")
    },
    ccInputProps: {
      label: t("neetoMolecules.emailForm.labels.cc"),
      name: "sendToCc",
      placeholder: t("neetoMolecules.emailForm.placeholders.commaSeparatedEmails")
    },
    emailInputProps: {
      id: "sendTo",
      name: "sendTo",
      label: t("neetoMolecules.emailForm.labels.sendTo"),
      placeholder: t("neetoMolecules.emailForm.placeholders.commaSeparatedEmails"),
      required: true
    }
  });
};

var SubjectField = function SubjectField(_ref) {
  var name = _ref.name,
    text = _ref.text,
    updateText = _ref.updateText,
    _ref$subjectVariables = _ref.subjectVariables,
    subjectVariables = _ref$subjectVariables === void 0 ? [] : _ref$subjectVariables,
    error = _ref.error,
    _ref$required = _ref.required,
    required = _ref$required === void 0 ? false : _ref$required,
    onBlur = _ref.onBlur;
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    isFieldFocusedOnce = _useState2[0],
    setIsFieldFocusedOnce = _useState2[1];
  var _useTranslation = useTranslation(),
    t = _useTranslation.t;
  var tagClickHandler = function tagClickHandler(_ref2) {
    var slug = _ref2.key,
      category = _ref2.category;
    var textAreaElement = document.querySelector("textarea[name=".concat(name, "]"));
    var splitIndex = isFieldFocusedOnce && textAreaElement ? textAreaElement.selectionEnd : text.length;
    var variable = category ? "".concat(category, ".").concat(slug) : slug;
    var updatedSubject = [text.slice(0, splitIndex), " {{".concat(variable, "}}"), text.slice(splitIndex)].join("");
    updateText(updatedSubject);
  };
  return /*#__PURE__*/jsxs(Fragment, {
    children: [/*#__PURE__*/jsx(Input$1, {
      error: error,
      name: name,
      onBlur: onBlur,
      required: required,
      label: t("neetoMolecules.emailForm.labels.subject"),
      size: "large",
      value: text,
      suffix: /*#__PURE__*/jsx(DynamicVariables, {
        variables: subjectVariables,
        dropdownProps: {
          className: "neeto-ui-dropdown__popup overflow-y-auto",
          buttonSize: "small"
        },
        onVariableClick: tagClickHandler
      }),
      onChange: withEventTargetValue(updateText),
      onFocus: function onFocus() {
        return setIsFieldFocusedOnce(true);
      }
    }), /*#__PURE__*/jsx(Typography, {
      className: "neeto-ui-text-gray-600 mt-2",
      "data-cy": "subject-input-variable-label",
      style: "body3",
      children: /*#__PURE__*/jsx(Trans, {
        components: {
          span: /*#__PURE__*/jsx("span", {
            className: "font-semibold"
          })
        },
        i18nKey: "neetoMolecules.emailForm.helpText",
        values: {
          type: "subject"
        }
      })
    })]
  });
};

function ownKeys$2(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var EmailForm = function EmailForm(_ref) {
  var _ref$messageVariables = _ref.messageVariables,
    messageVariables = _ref$messageVariables === void 0 ? [] : _ref$messageVariables,
    _ref$subjectVariables = _ref.subjectVariables,
    subjectVariables = _ref$subjectVariables === void 0 ? [] : _ref$subjectVariables,
    handleCancel = _ref.handleCancel,
    handleResetToDefault = _ref.handleResetToDefault,
    isLoading = _ref.isLoading,
    replyToFieldProps = _ref.replyToFieldProps,
    sendToFieldProps = _ref.sendToFieldProps,
    replyToOptions = _ref.replyToOptions,
    _ref$sendToOptions = _ref.sendToOptions,
    sendToOptions = _ref$sendToOptions === void 0 ? [] : _ref$sendToOptions,
    _ref$isUpdating = _ref.isUpdating,
    isUpdating = _ref$isUpdating === void 0 ? false : _ref$isUpdating,
    _ref$isResetting = _ref.isResetting,
    isResetting = _ref$isResetting === void 0 ? false : _ref$isResetting,
    _ref$showFields = _ref.showFields,
    showFields = _ref$showFields === void 0 ? true : _ref$showFields,
    _ref$className = _ref.className,
    className = _ref$className === void 0 ? "" : _ref$className,
    _ref$editorAddons = _ref.editorAddons,
    editorAddons = _ref$editorAddons === void 0 ? EDITOR_ADDONS : _ref$editorAddons,
    showResetToDefaultButton = _ref.showResetToDefaultButton,
    _ref$editorRef = _ref.editorRef,
    editorRef = _ref$editorRef === void 0 ? null : _ref$editorRef,
    _ref$defaultValues = _ref.defaultValues,
    defaultValues = _ref$defaultValues === void 0 ? {} : _ref$defaultValues;
  var _useTranslation = useTranslation(),
    t = _useTranslation.t;
  var _useContext = useContext(EmailFormContext),
    showSendToField = _useContext.showSendToField,
    showSendToAsRadio = _useContext.showSendToAsRadio,
    showReplyToField = _useContext.showReplyToField,
    showCcField = _useContext.showCcField,
    showBccField = _useContext.showBccField;
  var _useFormikContext = useFormikContext(),
    setFieldValue = _useFormikContext.setFieldValue,
    values = _useFormikContext.values,
    resetForm = _useFormikContext.resetForm;
  var normalizedValues = _objectSpread$2(_objectSpread$2({}, values), {}, {
    message: normalizeHtmlString(values.message)
  });
  var normalizedDefaultValues = _objectSpread$2(_objectSpread$2({}, defaultValues), {}, {
    message: normalizeHtmlString(defaultValues === null || defaultValues === void 0 ? void 0 : defaultValues.message)
  });
  normalizedDefaultValues.replyTo || (normalizedDefaultValues.replyTo = globalProps.user.email);
  var disabled = equals(normalizedValues, normalizedDefaultValues);
  var sendToFieldOptions = (sendToFieldProps === null || sendToFieldProps === void 0 ? void 0 : sendToFieldProps.options) || sendToOptions;
  var showSendToRadioField = showSendToField && showSendToAsRadio && isNotEmpty(sendToFieldOptions);
  var showSendToTextField = showSendToField && !showSendToRadioField;
  return /*#__PURE__*/jsxs("div", {
    "data-cy": "email-form",
    "data-testid": "email-form",
    className: classnames("neeto-notification-email-wrapper__form-container flex flex-1 flex-col items-start gap-2 !pb-0", _defineProperty({}, className, className)),
    children: [showFields && /*#__PURE__*/jsxs("div", {
      className: "flex w-full flex-col items-start justify-start gap-6",
      children: [/*#__PURE__*/jsx(Field, {
        name: "subject",
        children: function children(_ref2) {
          var _ref2$field = _ref2.field,
            value = _ref2$field.value,
            onBlur = _ref2$field.onBlur,
            _ref2$meta = _ref2.meta,
            error = _ref2$meta.error,
            touched = _ref2$meta.touched;
          return /*#__PURE__*/jsx("div", {
            className: "w-full",
            children: /*#__PURE__*/jsx(SubjectField, {
              onBlur: onBlur,
              subjectVariables: subjectVariables,
              required: true,
              error: touched && error ? t(error) : undefined,
              name: "subject",
              text: value,
              updateText: function updateText(text) {
                return setFieldValue("subject", text);
              }
            })
          });
        }
      }), showSendToRadioField && /*#__PURE__*/jsx(Radio, {
        "data-testid": "send-to-id",
        label: t("neetoMolecules.emailForm.labels.sendTo"),
        labelProps: {
          required: true
        },
        name: "sendToId",
        children: sendToFieldOptions.map(function (_ref3) {
          var label = _ref3.label,
            value = _ref3.value;
          return /*#__PURE__*/createElement(Radio.Item, {
            label: label,
            value: value,
            key: value
          });
        })
      }), /*#__PURE__*/jsx(SendToField, {
        showBccField: showBccField,
        showCcField: showCcField,
        showSendToTextField: showSendToTextField
      }), showReplyToField && /*#__PURE__*/jsx(ReplyToField, _objectSpread$2({
        options: replyToOptions
      }, replyToFieldProps)), /*#__PURE__*/jsxs("div", {
        className: "w-full",
        "data-cy": "message-input-container",
        children: [/*#__PURE__*/jsx(FormikEditor, {
          required: true,
          addons: editorAddons,
          "data-cy": "message-input-field",
          id: "form_message",
          label: t("neetoMolecules.emailForm.labels.message"),
          name: "message",
          ref: editorRef,
          variables: messageVariables,
          shouldUpdate: function shouldUpdate(nextProps, prevProps) {
            return notEqualsDeep(nextProps.variables, prevProps.variables);
          }
        }), /*#__PURE__*/jsx(Typography, {
          className: "neeto-ui-text-gray-500 mt-2",
          "data-cy": "message-input-variable-label",
          style: "body3",
          children: /*#__PURE__*/jsx(Trans, {
            i18nKey: "neetoMolecules.emailForm.helpText",
            values: {
              type: "message"
            },
            components: {
              span: /*#__PURE__*/jsx("span", {
                className: "font-semibold"
              })
            }
          })
        })]
      })]
    }), /*#__PURE__*/jsxs("div", {
      className: "neeto-ui-bg-white neeto-notification-email-wrapper__action-block z-10 flex w-full justify-between py-6 lg:sticky lg:bottom-0",
      children: [/*#__PURE__*/jsx(ActionBlock, {
        cancelButtonProps: {
          onClick: handleCancel
        },
        isSubmitting: isLoading || isUpdating
      }), showResetToDefaultButton && /*#__PURE__*/jsx("div", {
        className: "neeto-ui-action-block__wrapper",
        children: /*#__PURE__*/jsx(Button, {
          disabled: disabled,
          "data-cy": "resetToDefaultButton",
          label: t("neetoMolecules.emailForm.labels.resetToDefault"),
          loading: isResetting,
          style: "tertiary",
          onClick: function onClick() {
            resetForm();
            handleResetToDefault();
          }
        })
      })]
    })]
  });
};

var css = ".neeto-notification-email-wrapper{height:calc(100vh - 64px);height:calc(100dvh - 64px)}";
n(css,{});

function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var EmailFormComponent = function EmailFormComponent(_ref) {
  var _ref$onSubmit = _ref.onSubmit,
    onSubmit = _ref$onSubmit === void 0 ? noop : _ref$onSubmit,
    _ref$initialValues = _ref.initialValues,
    initialValues = _ref$initialValues === void 0 ? INITIAL_FORM_VALUES : _ref$initialValues,
    _children = _ref.children,
    formikProps = _ref.formikProps,
    validationSchema = _ref.validationSchema,
    _ref$showSendToField = _ref.showSendToField,
    showSendToField = _ref$showSendToField === void 0 ? false : _ref$showSendToField,
    _ref$showReplyToField = _ref.showReplyToField,
    showReplyToField = _ref$showReplyToField === void 0 ? false : _ref$showReplyToField,
    _ref$showSendToAsRadi = _ref.showSendToAsRadio,
    showSendToAsRadio = _ref$showSendToAsRadi === void 0 ? false : _ref$showSendToAsRadi,
    _ref$blockNavigation = _ref.blockNavigation,
    blockNavigation = _ref$blockNavigation === void 0 ? true : _ref$blockNavigation,
    _ref$showCcField = _ref.showCcField,
    showCcField = _ref$showCcField === void 0 ? false : _ref$showCcField,
    _ref$showBccField = _ref.showBccField,
    showBccField = _ref$showBccField === void 0 ? false : _ref$showBccField,
    _ref$isLoading = _ref.isLoading,
    isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading,
    _ref$maxEmails = _ref.maxEmails,
    maxEmails = _ref$maxEmails === void 0 ? 10 : _ref$maxEmails,
    _ref$emailFormProps = _ref.emailFormProps,
    emailFormProps = _ref$emailFormProps === void 0 ? {} : _ref$emailFormProps,
    _ref$emailPreviewProp = _ref.emailPreviewProps,
    emailPreviewProps = _ref$emailPreviewProp === void 0 ? {} : _ref$emailPreviewProp,
    _ref$headerProps = _ref.headerProps,
    headerProps = _ref$headerProps === void 0 ? {} : _ref$headerProps,
    _ref$tooltipProps = _ref.tooltipProps,
    tooltipProps = _ref$tooltipProps === void 0 ? {} : _ref$tooltipProps,
    _ref$switchProps = _ref.switchProps,
    switchProps = _ref$switchProps === void 0 ? {} : _ref$switchProps,
    _ref$mobilePreviewPro = _ref.mobilePreviewProps,
    mobilePreviewProps = _ref$mobilePreviewPro === void 0 ? {} : _ref$mobilePreviewPro;
  var formatBody = emailPreviewProps.formatBody,
    formatSubject = emailPreviewProps.formatSubject,
    bodyVariables = emailPreviewProps.bodyVariables,
    subjectVariables = emailPreviewProps.subjectVariables;
  var shouldShowFields = function shouldShowFields(values) {
    return isEmpty(switchProps) || values.isEnabled;
  };
  return /*#__PURE__*/jsx(EmailFormProvider, {
    formikProps: formikProps,
    initialValues: initialValues,
    maxEmails: maxEmails,
    onSubmit: onSubmit,
    showBccField: showBccField,
    showCcField: showCcField,
    showReplyToField: showReplyToField,
    showSendToAsRadio: showSendToAsRadio,
    showSendToField: showSendToField,
    validationSchema: validationSchema,
    children: function children(_ref2) {
      var _values$sendTo;
      var values = _ref2.values,
        isSubmitting = _ref2.isSubmitting;
      return /*#__PURE__*/jsxs("div", {
        className: "neeto-notification-email-wrapper flex flex-grow flex-col overflow-y-auto lg:flex-row",
        children: [/*#__PURE__*/jsxs("div", {
          className: "neeto-notification-email-wrapper__form-wrapper flex w-full flex-col px-5 md:px-10 lg:h-full lg:w-1/2 lg:overflow-y-auto",
          children: [blockNavigation && /*#__PURE__*/jsx(BlockNavigation, {}), isNotEmpty(headerProps) && /*#__PURE__*/jsx(Header, _objectSpread$1({
            className: "px-0",
            size: "small"
          }, headerProps)), isNotEmpty(switchProps) && /*#__PURE__*/jsx("div", {
            className: "flex items-center justify-between gap-y-0.5 pb-6",
            children: /*#__PURE__*/jsx(Tooltip, _objectSpread$1(_objectSpread$1({
              disabled: !(switchProps !== null && switchProps !== void 0 && switchProps.disabled),
              position: "top"
            }, tooltipProps), {}, {
              children: /*#__PURE__*/jsx("div", {
                className: "flex items-center gap-2",
                children: /*#__PURE__*/jsx(Switch, _objectSpread$1({
                  "data-testid": "switch",
                  name: "isEnabled"
                }, switchProps))
              })
            }))
          }), shouldShowFields(values) && _children, /*#__PURE__*/jsx(EmailForm, _objectSpread$1({
            isLoading: isSubmitting || isLoading,
            isUpdating: isSubmitting || isLoading,
            showFields: shouldShowFields(values)
          }, emailFormProps))]
        }), shouldShowFields(values) && /*#__PURE__*/jsx(MobilePreviewHeader, _objectSpread$1({
          className: "lg:hidden"
        }, mobilePreviewProps)), shouldShowFields(values) && /*#__PURE__*/jsx("div", {
          className: "neeto-notification-email-wrapper__preview-wrapper neeto-ui-bg-gray-100 w-full px-6 py-10 lg:w-1/2 lg:overflow-y-auto",
          children: /*#__PURE__*/jsx(EmailPreview, _objectSpread$1({
            body: resolveContent(values.message, formatBody, bodyVariables),
            from: values.sendFrom,
            to: pluck("value", (_values$sendTo = values === null || values === void 0 ? void 0 : values.sendTo) !== null && _values$sendTo !== void 0 ? _values$sendTo : []),
            subject: resolveContent(values.subject, formatSubject, subjectVariables)
          }, emailPreviewProps))
        })]
      });
    }
  });
};

function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var EmailFormProvider = function EmailFormProvider(_ref) {
  var _ref$onSubmit = _ref.onSubmit,
    onSubmit = _ref$onSubmit === void 0 ? noop : _ref$onSubmit,
    _ref$initialValues = _ref.initialValues,
    initialValues = _ref$initialValues === void 0 ? INITIAL_FORM_VALUES : _ref$initialValues,
    children = _ref.children,
    formikProps = _ref.formikProps,
    _ref$validationSchema = _ref.validationSchema,
    customValidations = _ref$validationSchema === void 0 ? {} : _ref$validationSchema,
    _ref$showSendToField = _ref.showSendToField,
    showSendToField = _ref$showSendToField === void 0 ? false : _ref$showSendToField,
    _ref$showReplyToField = _ref.showReplyToField,
    showReplyToField = _ref$showReplyToField === void 0 ? false : _ref$showReplyToField,
    _ref$showSendToAsRadi = _ref.showSendToAsRadio,
    showSendToAsRadio = _ref$showSendToAsRadi === void 0 ? false : _ref$showSendToAsRadi,
    _ref$showCcField = _ref.showCcField,
    showCcField = _ref$showCcField === void 0 ? false : _ref$showCcField,
    _ref$showBccField = _ref.showBccField,
    showBccField = _ref$showBccField === void 0 ? false : _ref$showBccField,
    _ref$maxEmails = _ref.maxEmails,
    maxEmails = _ref$maxEmails === void 0 ? 10 : _ref$maxEmails;
  return /*#__PURE__*/jsx("div", {
    className: "neeto-notification-email-outer-wrapper",
    "data-testid": "email-form-provider",
    children: /*#__PURE__*/jsx(EmailFormContext.Provider, {
      value: {
        showSendToField: showSendToField,
        showSendToAsRadio: showSendToAsRadio,
        showReplyToField: showReplyToField,
        showCcField: showCcField,
        showBccField: showBccField
      },
      children: /*#__PURE__*/jsx(Form, {
        className: "neeto-notification-email-inner-wrapper",
        formikProps: _objectSpread({
          enableReinitialize: true,
          validationSchema: getValidationSchema({
            showSendToField: showSendToField,
            showReplyToField: showReplyToField,
            showSendToAsRadio: showSendToAsRadio,
            customValidations: customValidations,
            maxEmails: maxEmails
          }),
          initialValues: _objectSpread(_objectSpread({}, initialValues), {}, {
            replyTo: initialValues.replyTo || globalProps.user.email
          }),
          onSubmit: onSubmit
        }, formikProps),
        children: children
      })
    })
  });
};

export { EmailForm, EmailFormProvider, EmailPreview, EmailFormComponent as default };
//# sourceMappingURL=EmailForm.js.map
