import { jsxs as B, Fragment as L, jsx as a } from "react/jsx-runtime";
import { l as j } from "./index.C1ZfizMq.js";
import { a as W } from "./index.CfQlFjZU.js";
import { n as $ } from "./index.B0wX8xO7.js";
import { useState as V, useEffect as y, useCallback as n, useMemo as A } from "react";
import { b as G } from "./index.dWlEA7uO.js";
import { S as b, M as K } from "./shared.EdGf6tcG.js";
import { B as U } from "./Button.CpTwUWVr.js";
import { a as q } from "./message.CHKnnsjy.js";
import { n as I } from "./url.D3ItqZWD.js";
import { u as H } from "./shortVideoModule.BlUq1dqv.js";
import { S as J } from "./ShortVideoField.Bl0CE98i.js";
import { u as Q } from "./ItemCreationContext.CFI6PyWk.js";
const T = ({
  previousPageUrl: g,
  type: p,
  existingVideos: h,
  loading: i,
  onDone: l,
  onCancel: c,
  alternative: t,
  errors: u
}) => {
  const [k, d] = V(!1), [e, C] = V(h || [""]), [M, v] = V(
    Array.from({ length: h?.length || 0 }, () => null)
  ), S = H(p);
  y(() => {
    u && v(u);
  }, [u]);
  const m = n(
    (o) => {
      const s = o.trim();
      return s === "" || S.videoRegex.test(s);
    },
    [S.videoRegex]
  ), R = A(() => e.filter((o) => o.trim() !== "").filter(m).length > 0, [e, m]), w = A(() => e.map((o, s) => {
    const r = !m(o) || M[s];
    return {
      value: o,
      error: r
    };
  }), [e, M, m]), E = n((o, s) => {
    C((r) => {
      const f = [...r];
      return f[o] = s, f;
    }), v((r) => {
      const f = [...r];
      return f[o] = null, f;
    });
  }, []), P = n(() => {
    C((o) => [...o, ""]);
  }, []), N = n(() => {
    const o = e.map((s) => {
      const r = s.trim();
      return r === "" || !m(r) ? { url: r, valid: !1 } : { url: I(r), valid: !0 };
    });
    l(o);
  }, [e, m, l]), x = n(() => {
    d(!0);
  }, []), z = n(() => {
    d(!1);
  }, []), D = n(() => {
    d(!1), c();
  }, [c]), F = A(() => !!t && !!t.regex && e.some((o) => t.regex.test(o)), [t, e]), O = n(() => {
    t && t.onClick(
      e.filter((o) => o.trim() !== "").map(I)
    );
  }, [t, e]), Y = [
    {
      label: "Previous",
      semantic: b.SECONDARY,
      onClick: x,
      disabled: i
    },
    {
      label: "Done",
      semantic: b.PRIMARY,
      onClick: N,
      disabled: !R || i,
      loading: i
    }
  ];
  return Q({
    previousPageUrl: g,
    buttons: Y,
    onClickPrevious: x,
    title: `Add ${S.platformName} ${S.plural}`,
    showWarningModal: k,
    onKeepEditing: z,
    onGoBack: D
  }), {
    videos: w,
    onVideoChange: E,
    onVideoAdd: P,
    type: p,
    loading: i,
    alternative: t,
    showAlternativePrompt: F,
    onAlternativeClick: O
  };
}, X = ({
  videos: g,
  onVideoAdd: p,
  onVideoChange: h,
  type: i,
  loading: l,
  alternative: c,
  showAlternativePrompt: t,
  onAlternativeClick: u
}) => /* @__PURE__ */ B(L, { children: [
  /* @__PURE__ */ a(
    j,
    {
      values: g,
      layout: ({ value: k, error: d }, e) => /* @__PURE__ */ a(
        J,
        {
          type: i,
          value: k,
          error: d,
          onChange: (C) => h(e, C),
          disabled: l
        }
      )
    }
  ),
  /* @__PURE__ */ a(
    $,
    {
      value: t,
      then: /* @__PURE__ */ a(
        q,
        {
          text: c?.message || "",
          semantic: K.INFO,
          buttonProps: {
            label: c?.buttonLabel || "",
            semantic: b.SECONDARY,
            size: "xsmall",
            onClick: u
          }
        }
      )
    }
  ),
  /* @__PURE__ */ a(
    U,
    {
      label: "Add Video",
      semantic: b.SECONDARY,
      size: "small",
      prefixIcon: /* @__PURE__ */ a(G, { size: 24 }),
      onClick: p,
      disabled: l
    }
  )
] }), uo = W(
  X,
  T
);
export {
  uo as S
};
