import { aM as oe, aN as se, aR as s, aL as ie, aS as g, aT as C, aU as I, aK as e, aP as ce, S as u, K as i, n as r, e as b, aq as P, aV as de, V as re } from "./index-GTnBs7av.js";
import { useState as v } from "react";
import { A as he } from "./AppCard-Q28K7Yaw.js";
import { u as ue } from "./useIsAppEnabled-7UywjsU4.js";
const Ce = 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, K = t("ifFreeEmailDomainSkipOwnerCheck") ?? !1, Y = t("skipContactCreation"), z = t("createLeadIfAccountNull"), $ = t("createNewContactUnderAccount"), R = t("createEventOn") ?? s.CONTACT, S = t("onBookingWriteToEventObject") ?? !1, m = t("onBookingWriteToEventObjectMap") ?? {}, q = t("createEventOnLeadCheckForContact") ?? !1, W = t("onBookingChangeRecordOwner") ?? !1, H = t("onBookingChangeRecordOwnerName") ?? [], F = t("sendNoShowAttendeeData") ?? !1, X = t("sendNoShowAttendeeDataField") ?? "", D = t("onBookingWriteToRecord") ?? !1, c = t("onBookingWriteToRecordFields") ?? {}, J = 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, Q] = v(
    O.find((n) => n.value === R) ?? O[0]
  ), _ = [
    { label: a("text"), value: g.TEXT },
    { label: a("date"), value: g.DATE },
    { label: a("phone").charAt(0).toUpperCase() + a("phone").slice(1), value: g.PHONE }
  ], [p, Z] = v(_[0]), f = [
    { label: a("on_every_booking"), value: C.EVERY_BOOKING },
    { label: a("only_if_field_is_empty"), value: C.FIELD_EMPTY }
  ], [ee, ne] = v(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] = v(k[0]), [o, j] = v({
    field: "",
    fieldType: p.value,
    value: "",
    whenToWrite: C.FIELD_EMPTY
  }), T = [
    { label: a("contact"), value: s.CONTACT },
    { label: a("salesforce_lead"), value: s.LEAD },
    { label: a("account"), value: s.ACCOUNT }
  ], [le, te] = v(
    T.find((n) => n.value === V) ?? T[0]
  ), [d, N] = v({
    field: "",
    value: ""
  }), L = () => /* @__PURE__ */ e.jsx(
    i,
    {
      label: a("salesforce_create_new_contact_under_account"),
      labelOnLeading: !0,
      checked: $,
      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 && (Q(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: J,
            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: Y,
            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: q,
              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: z,
              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(m).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: m[n], readOnly: !0 }) }),
                /* @__PURE__ */ e.jsx("div", { children: /* @__PURE__ */ e.jsx(
                  b,
                  {
                    StartIcon: "trash",
                    variant: "icon",
                    color: "destructive",
                    onClick: () => {
                      const h = m;
                      delete m[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(
              b,
              {
                className: "mt-2",
                size: "sm",
                disabled: !(d.field && d.value),
                onClick: () => {
                  if (Object.keys(m).includes(
                    d.field.trim()
                  )) {
                    P("Field already exists", "error");
                    return;
                  }
                  l("onBookingWriteToEventObjectMap", {
                    ...m,
                    [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 === g.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(
                  b,
                  {
                    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) => j({
                      ...o,
                      field: n.target.value
                    })
                  }
                ) }),
                /* @__PURE__ */ e.jsx("div", { children: /* @__PURE__ */ e.jsx(
                  u,
                  {
                    options: _,
                    value: p,
                    onChange: (n) => {
                      n && (Z(n), j({
                        ...o,
                        fieldType: n.value,
                        ...n.value === g.DATE && { value: B.value }
                      }));
                    }
                  }
                ) }),
                /* @__PURE__ */ e.jsx("div", { children: p.value === g.DATE ? /* @__PURE__ */ e.jsx(
                  u,
                  {
                    options: k,
                    value: B,
                    onChange: (n) => {
                      n && (ae(n), j({
                        ...o,
                        value: n.value
                      }));
                    }
                  }
                ) : /* @__PURE__ */ e.jsx(
                  r,
                  {
                    value: o.value,
                    onChange: (n) => j({
                      ...o,
                      value: n.target.value
                    })
                  }
                ) }),
                /* @__PURE__ */ e.jsx("div", { children: /* @__PURE__ */ e.jsx(
                  u,
                  {
                    options: f,
                    value: ee,
                    onChange: (n) => {
                      n && (ne(n), j({
                        ...o,
                        whenToWrite: n.value
                      }));
                    }
                  }
                ) })
              ] })
            ] }),
            /* @__PURE__ */ e.jsx(
              b,
              {
                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
                    }
                  }), j({
                    field: "",
                    fieldType: p.value,
                    value: "",
                    whenToWrite: C.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: H,
              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: K,
                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: X,
                onChange: (n) => l("sendNoShowAttendeeDataField", n.target.value)
              }
            )
          ] }) : null
        ] })
      ] })
    }
  );
};
export {
  Ce as default
};
