import { aY as oe, aZ as se, b8 as s, aX as ie, b9 as v, ba as p, bb as I, aW as e, a$ as ce, S as u, K as i, n as r, e as C, aq as P, bc as de, V as re } from "./index-6jcTChn4.js";
import { useState as m } from "react";
import { A as he } from "./AppCard-YGWCah1h.js";
import { u as ue } from "./useIsAppEnabled-i8k_pVtm.js";
const pe = function({ app: w, eventType: E }) {
  var y;
  const U = oe.usePathname(), { getAppData: t, setAppData: l, disabled: me } = se(), { enabled: M, updateEnabled: G } = ue(w), A = t("roundRobinLeadSkip"), V = t("roundRobinSkipCheckRecordOn") ?? s.CONTACT, Y = t("ifFreeEmailDomainSkipOwnerCheck") ?? !1, K = t("skipContactCreation"), $ = t("createLeadIfAccountNull"), z = t("createNewContactUnderAccount"), R = t("createEventOn") ?? s.CONTACT, S = t("onBookingWriteToEventObject") ?? !1, j = t("onBookingWriteToEventObjectMap") ?? {}, X = t("createEventOnLeadCheckForContact") ?? !1, W = t("onBookingChangeRecordOwner") ?? !1, q = t("onBookingChangeRecordOwnerName") ?? [], F = t("sendNoShowAttendeeData") ?? !1, H = t("sendNoShowAttendeeDataField") ?? "", D = t("onBookingWriteToRecord") ?? !1, c = t("onBookingWriteToRecordFields") ?? {}, Z = t("ignoreGuests") ?? !1, { t: a } = ie(), O = [
    { label: a("contact"), value: s.CONTACT },
    { label: a("salesforce_lead"), value: s.LEAD },
    { label: a("salesforce_contact_under_account"), value: s.ACCOUNT }
  ], [x, J] = m(
    O.find((n) => n.value === R) ?? O[0]
  ), _ = [
    { label: a("text"), value: v.TEXT },
    { label: a("date"), value: v.DATE },
    { label: a("phone").charAt(0).toUpperCase() + a("phone").slice(1), value: v.PHONE },
    { label: a("custom"), value: v.CUSTOM }
  ], [b, Q] = m(_[0]), f = [
    { label: a("on_every_booking"), value: p.EVERY_BOOKING },
    { label: a("only_if_field_is_empty"), value: p.FIELD_EMPTY }
  ], [ee, ne] = m(f[0]), k = [
    { label: a("booking_start_date"), value: I.BOOKING_START_DATE },
    { label: a("booking_created_date"), value: I.BOOKING_CREATED_DATE }
  ], [B, ae] = m(k[0]), [o, g] = m({
    field: "",
    fieldType: b.value,
    value: "",
    whenToWrite: p.FIELD_EMPTY
  }), T = [
    { label: a("contact"), value: s.CONTACT },
    { label: a("salesforce_lead"), value: s.LEAD },
    { label: a("account"), value: s.ACCOUNT }
  ], [le, te] = m(
    T.find((n) => n.value === V) ?? T[0]
  ), [d, N] = m({
    field: "",
    value: ""
  }), L = () => /* @__PURE__ */ e.jsx(
    i,
    {
      label: a("salesforce_create_new_contact_under_account"),
      labelOnLeading: !0,
      checked: z,
      onCheckedChange: (n) => {
        l("createNewContactUnderAccount", n);
      }
    }
  );
  return /* @__PURE__ */ e.jsx(
    he,
    {
      returnTo: `${ce}${U}?tabName=apps`,
      app: w,
      teamId: ((y = E.team) == null ? void 0 : y.id) || void 0,
      switchOnClick: (n) => {
        G(n);
      },
      switchChecked: M,
      hideSettingsIcon: !0,
      children: /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
        /* @__PURE__ */ e.jsxs("div", { className: "mb-4 ml-2", children: [
          /* @__PURE__ */ e.jsx("label", { className: "text-emphasis mb-2 align-text-top text-sm font-medium", children: a("salesforce_create_record_as") }),
          /* @__PURE__ */ e.jsx(
            u,
            {
              className: "mt-2 w-60",
              options: O,
              value: x,
              onChange: (n) => {
                n && (J(n), l("createEventOn", n.value));
              }
            }
          )
        ] }),
        /* @__PURE__ */ e.jsx("div", { className: "mb-4", children: /* @__PURE__ */ e.jsx(
          i,
          {
            label: a("salesforce_ignore_guests"),
            labelOnLeading: !0,
            checked: Z,
            onCheckedChange: (n) => {
              l("ignoreGuests", n);
            }
          }
        ) }),
        x.value === s.CONTACT ? /* @__PURE__ */ e.jsx("div", { children: /* @__PURE__ */ e.jsx(
          i,
          {
            label: a("skip_contact_creation", { appName: "Salesforce" }),
            labelOnLeading: !0,
            checked: K,
            onCheckedChange: (n) => {
              l("skipContactCreation", n);
            }
          }
        ) }) : null,
        x.value === s.LEAD ? /* @__PURE__ */ e.jsxs("div", { children: [
          /* @__PURE__ */ e.jsx(
            i,
            {
              label: a("salesforce_create_event_on_contact"),
              labelOnLeading: !0,
              checked: X,
              onCheckedChange: (n) => {
                l("createEventOnLeadCheckForContact", n);
              }
            }
          ),
          /* @__PURE__ */ e.jsx("div", { className: "mt-4", children: /* @__PURE__ */ e.jsx(L, {}) })
        ] }) : null,
        x.value === s.ACCOUNT ? /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
          /* @__PURE__ */ e.jsx("div", { className: "mb-4", children: /* @__PURE__ */ e.jsx(L, {}) }),
          /* @__PURE__ */ e.jsx("div", { children: /* @__PURE__ */ e.jsx(
            i,
            {
              label: a("salesforce_if_account_does_not_exist"),
              labelOnLeading: !0,
              checked: $,
              onCheckedChange: (n) => {
                l("createLeadIfAccountNull", n);
              }
            }
          ) })
        ] }) : null,
        /* @__PURE__ */ e.jsxs("div", { className: "mt-4", children: [
          /* @__PURE__ */ e.jsx(
            i,
            {
              label: a("on_booking_write_to_event_object"),
              labelOnLeading: !0,
              checked: S,
              onCheckedChange: (n) => {
                l("onBookingWriteToEventObject", n);
              }
            }
          ),
          S ? /* @__PURE__ */ e.jsxs("div", { className: "ml-2 mt-2", children: [
            /* @__PURE__ */ e.jsxs("div", { className: "grid grid-cols-3 gap-4", children: [
              /* @__PURE__ */ e.jsx("div", { children: a("field_name") }),
              /* @__PURE__ */ e.jsx("div", { children: a("value") })
            ] }),
            /* @__PURE__ */ e.jsxs("div", { children: [
              Object.keys(j).map((n) => /* @__PURE__ */ e.jsxs("div", { className: "mt-2 grid grid-cols-3 gap-4", children: [
                /* @__PURE__ */ e.jsx("div", { children: /* @__PURE__ */ e.jsx(r, { value: n, readOnly: !0 }) }),
                /* @__PURE__ */ e.jsx("div", { children: /* @__PURE__ */ e.jsx(r, { value: j[n], readOnly: !0 }) }),
                /* @__PURE__ */ e.jsx("div", { children: /* @__PURE__ */ e.jsx(
                  C,
                  {
                    StartIcon: "trash",
                    variant: "icon",
                    color: "destructive",
                    onClick: () => {
                      const h = j;
                      delete j[n], l("onBookingWriteToEventObjectMap", h);
                    }
                  }
                ) })
              ] }, n)),
              /* @__PURE__ */ e.jsxs("div", { className: "mt-2 grid grid-cols-3 gap-4", children: [
                /* @__PURE__ */ e.jsx("div", { children: /* @__PURE__ */ e.jsx(
                  r,
                  {
                    value: d.field,
                    onChange: (n) => N({
                      ...d,
                      field: n.target.value
                    })
                  }
                ) }),
                /* @__PURE__ */ e.jsx("div", { children: /* @__PURE__ */ e.jsx(
                  r,
                  {
                    value: d.value,
                    onChange: (n) => N({
                      ...d,
                      value: n.target.value
                    })
                  }
                ) })
              ] })
            ] }),
            /* @__PURE__ */ e.jsx(
              C,
              {
                className: "mt-2",
                size: "sm",
                disabled: !(d.field && d.value),
                onClick: () => {
                  if (Object.keys(j).includes(
                    d.field.trim()
                  )) {
                    P("Field already exists", "error");
                    return;
                  }
                  l("onBookingWriteToEventObjectMap", {
                    ...j,
                    [d.field.trim()]: d.value.trim()
                  }), N({ field: "", value: "" });
                },
                children: a("add_new_field")
              }
            )
          ] }) : null
        ] }),
        /* @__PURE__ */ e.jsxs("div", { className: "mt-4", children: [
          /* @__PURE__ */ e.jsx(
            i,
            {
              label: a("salesforce_on_booking_write_to_record", { record: R }),
              labelOnLeading: !0,
              checked: D,
              onCheckedChange: (n) => {
                l("onBookingWriteToRecord", n);
              }
            }
          ),
          D ? /* @__PURE__ */ e.jsxs("div", { className: "ml-2 mt-2", children: [
            /* @__PURE__ */ e.jsxs("div", { className: "grid grid-cols-5 gap-4", children: [
              /* @__PURE__ */ e.jsx("div", { children: a("field_name") }),
              /* @__PURE__ */ e.jsx("div", { children: a("field_type") }),
              /* @__PURE__ */ e.jsx("div", { children: a("value") }),
              /* @__PURE__ */ e.jsx("div", { children: a("when_to_write") })
            ] }),
            /* @__PURE__ */ e.jsxs("div", { children: [
              Object.keys(c).map((n) => /* @__PURE__ */ e.jsxs("div", { className: "mt-2 grid grid-cols-5 gap-4", children: [
                /* @__PURE__ */ e.jsx("div", { children: /* @__PURE__ */ e.jsx(r, { value: n, readOnly: !0 }) }),
                /* @__PURE__ */ e.jsx("div", { children: /* @__PURE__ */ e.jsx(
                  u,
                  {
                    value: _.find(
                      (h) => h.value === c[n].fieldType
                    ),
                    isDisabled: !0
                  }
                ) }),
                /* @__PURE__ */ e.jsx("div", { children: c[n].fieldType === v.DATE ? /* @__PURE__ */ e.jsx(
                  u,
                  {
                    value: k.find(
                      (h) => h.value === c[n].value
                    ),
                    isDisabled: !0
                  }
                ) : /* @__PURE__ */ e.jsx(r, { value: c[n].value, readOnly: !0 }) }),
                /* @__PURE__ */ e.jsx("div", { children: /* @__PURE__ */ e.jsx(
                  u,
                  {
                    value: f.find(
                      (h) => h.value === c[n].whenToWrite
                    ),
                    isDisabled: !0
                  }
                ) }),
                /* @__PURE__ */ e.jsx("div", { children: /* @__PURE__ */ e.jsx(
                  C,
                  {
                    StartIcon: "trash",
                    variant: "icon",
                    color: "destructive",
                    onClick: () => {
                      const h = c;
                      delete c[n], l("onBookingWriteToRecordFields", h);
                    }
                  }
                ) })
              ] }, n)),
              /* @__PURE__ */ e.jsxs("div", { className: "mt-2 grid grid-cols-5 gap-4", children: [
                /* @__PURE__ */ e.jsx("div", { children: /* @__PURE__ */ e.jsx(
                  r,
                  {
                    value: o.field,
                    onChange: (n) => g({
                      ...o,
                      field: n.target.value
                    })
                  }
                ) }),
                /* @__PURE__ */ e.jsx("div", { children: /* @__PURE__ */ e.jsx(
                  u,
                  {
                    options: _,
                    value: b,
                    onChange: (n) => {
                      n && (Q(n), g({
                        ...o,
                        fieldType: n.value,
                        ...n.value === v.DATE && { value: B.value }
                      }));
                    }
                  }
                ) }),
                /* @__PURE__ */ e.jsx("div", { children: b.value === v.DATE ? /* @__PURE__ */ e.jsx(
                  u,
                  {
                    options: k,
                    value: B,
                    onChange: (n) => {
                      n && (ae(n), g({
                        ...o,
                        value: n.value
                      }));
                    }
                  }
                ) : /* @__PURE__ */ e.jsx(
                  r,
                  {
                    value: o.value,
                    onChange: (n) => g({
                      ...o,
                      value: n.target.value
                    })
                  }
                ) }),
                /* @__PURE__ */ e.jsx("div", { children: /* @__PURE__ */ e.jsx(
                  u,
                  {
                    options: f,
                    value: ee,
                    onChange: (n) => {
                      n && (ne(n), g({
                        ...o,
                        whenToWrite: n.value
                      }));
                    }
                  }
                ) })
              ] })
            ] }),
            /* @__PURE__ */ e.jsx(
              C,
              {
                className: "mt-2",
                size: "sm",
                disabled: !(o.field && o.fieldType && o.value && o.whenToWrite),
                onClick: () => {
                  if (Object.keys(c).includes(
                    d.field.trim()
                  )) {
                    P("Field already exists", "error");
                    return;
                  }
                  l("onBookingWriteToRecordFields", {
                    ...c,
                    [o.field.trim()]: {
                      fieldType: o.fieldType,
                      value: o.value,
                      whenToWrite: o.whenToWrite
                    }
                  }), g({
                    field: "",
                    fieldType: b.value,
                    value: "",
                    whenToWrite: p.FIELD_EMPTY
                  });
                },
                children: a("add_new_field")
              }
            )
          ] }) : null
        ] }),
        /* @__PURE__ */ e.jsx("div", { className: "mt-4", children: /* @__PURE__ */ e.jsx(
          i,
          {
            label: "Change record owner on booking",
            labelOnLeading: !0,
            checked: W,
            onCheckedChange: (n) => {
              l("onBookingChangeRecordOwner", n);
            }
          }
        ) }),
        W ? /* @__PURE__ */ e.jsxs("div", { className: "ml-2 mt-2", children: [
          /* @__PURE__ */ e.jsx("p", { className: "mb-2", children: a("salesforce_owner_name_to_change") }),
          /* @__PURE__ */ e.jsx(
            r,
            {
              value: q,
              onChange: (n) => l("onBookingChangeRecordOwnerName", n.target.value)
            }
          )
        ] }) : null,
        E.schedulingType === de.ROUND_ROBIN ? /* @__PURE__ */ e.jsxs("div", { className: "mt-4", children: [
          /* @__PURE__ */ e.jsx(
            i,
            {
              label: a("salesforce_book_directly_with_attendee_owner"),
              labelOnLeading: !0,
              checked: A,
              onCheckedChange: (n) => {
                l("roundRobinLeadSkip", n), n && l("enabled", n);
              }
            }
          ),
          A ? /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
            /* @__PURE__ */ e.jsxs("div", { className: "my-4 ml-2", children: [
              /* @__PURE__ */ e.jsx("label", { className: "text-emphasis mb-2 align-text-top text-sm font-medium", children: a("salesforce_check_owner_of") }),
              /* @__PURE__ */ e.jsx(
                u,
                {
                  className: "mt-2 w-60",
                  options: T,
                  value: le,
                  onChange: (n) => {
                    n && (te(n), l("roundRobinSkipCheckRecordOn", n.value));
                  }
                }
              )
            ] }),
            /* @__PURE__ */ e.jsx("div", { className: "my-4", children: /* @__PURE__ */ e.jsx(
              i,
              {
                label: a("salesforce_if_free_email_domain_skip_owner_check"),
                labelOnLeading: !0,
                checked: Y,
                onCheckedChange: (n) => {
                  l("ifFreeEmailDomainSkipOwnerCheck", n);
                }
              }
            ) })
          ] }) : null,
          /* @__PURE__ */ e.jsx(re, { className: "mt-2", severity: "neutral", title: a("skip_rr_description") })
        ] }) : null,
        /* @__PURE__ */ e.jsxs("div", { className: "ml-2 mt-4", children: [
          /* @__PURE__ */ e.jsx(
            i,
            {
              label: "Send no show attendee data to event object",
              checked: F,
              onCheckedChange: (n) => {
                l("sendNoShowAttendeeData", n);
              }
            }
          ),
          F ? /* @__PURE__ */ e.jsxs("div", { className: "mt-2", children: [
            /* @__PURE__ */ e.jsx("p", { className: "mb-2", children: "Field name to check (must be checkbox data type)" }),
            /* @__PURE__ */ e.jsx(
              r,
              {
                value: H,
                onChange: (n) => l("sendNoShowAttendeeDataField", n.target.value)
              }
            )
          ] }) : null
        ] })
      ] })
    }
  );
};
export {
  pe as default
};
