'use client';

import { c as _c } from "react/compiler-runtime";
import { useAuth, useConfig, useEntityVisibility } from '@payloadcms/ui';
import * as React from 'react';
const filterRichTextCollections = (collections, options) => {
  return collections.filter(({
    slug,
    admin: {
      enableRichTextRelationship
    },
    upload
  }) => {
    if (!options?.visibleEntities.collections.includes(slug)) {
      return false;
    }
    if (options?.uploads) {
      return enableRichTextRelationship && Boolean(upload) === true;
    }
    return upload ? false : enableRichTextRelationship;
  });
};
export const EnabledRelationshipsCondition = props => {
  const $ = _c(16);
  let children;
  let rest;
  let t0;
  if ($[0] !== props) {
    ({
      children,
      uploads: t0,
      ...rest
    } = props);
    $[0] = props;
    $[1] = children;
    $[2] = rest;
    $[3] = t0;
  } else {
    children = $[1];
    rest = $[2];
    t0 = $[3];
  }
  const uploads = t0 === undefined ? false : t0;
  const {
    config: t1
  } = useConfig();
  const {
    collections
  } = t1;
  const {
    user
  } = useAuth();
  const {
    visibleEntities
  } = useEntityVisibility();
  let t2;
  if ($[4] !== collections || $[5] !== uploads || $[6] !== user || $[7] !== visibleEntities) {
    t2 = () => filterRichTextCollections(collections, {
      uploads,
      user,
      visibleEntities
    }).map(_temp);
    $[4] = collections;
    $[5] = uploads;
    $[6] = user;
    $[7] = visibleEntities;
    $[8] = t2;
  } else {
    t2 = $[8];
  }
  const [enabledCollectionSlugs] = React.useState(t2);
  if (!enabledCollectionSlugs.length) {
    return null;
  }
  let t3;
  if ($[9] !== children || $[10] !== enabledCollectionSlugs || $[11] !== rest) {
    let t4;
    if ($[13] !== enabledCollectionSlugs || $[14] !== rest) {
      t4 = {
        ...rest,
        enabledCollectionSlugs
      };
      $[13] = enabledCollectionSlugs;
      $[14] = rest;
      $[15] = t4;
    } else {
      t4 = $[15];
    }
    t3 = React.cloneElement(children, t4);
    $[9] = children;
    $[10] = enabledCollectionSlugs;
    $[11] = rest;
    $[12] = t3;
  } else {
    t3 = $[12];
  }
  return t3;
};
function _temp(t0) {
  const {
    slug
  } = t0;
  return slug;
}
//# sourceMappingURL=EnabledRelationshipsCondition.js.map