<commit_before>
<%
  raw_model = content.is_a?(ContentSerializer) ? content.raw_model : content
%>

<div id="<%= category[:name].gsub("'", '') %>_panel" class="row panel" style="display: none">
  <% if category[:name] == 'gallery' %>
    <%= render partial: 'content/form/gallery/panel', locals: { f: f, content: content } %>
  <% end %>

  <% if category[:name] == 'contributors' %>
    <%# todo reorganize the files for all these panels? %>
    <%= render partial: 'content/form/contributors', locals: { f: f, content: content } %>
  <% end %>

  <% category[:fields].each do |field| %>
    <div class="col s12 m12 l12">
      <% if field[:type] == 'link' %>
        <%# Relation-setting UI %>
        <% through_class = raw_model.class.reflect_on_association(field[:old_column_source]).options[:through].to_s %>
        <%=
          render 'content/form/relation_input',
            f: f,
            attribute: field[:old_column_source],
            label: field[:label],
            relation: through_class
        %>

      <% elsif field[:type] == 'universe' %>
        <div class="content-field">
          <div class="input-field">
            <%= f.label field[:id], field[:label] %><br />

            <% if !f.object.persisted? || (f.object.persisted? && f.object.universe && f.object.universe.user == current_user) || f.object.universe_id.nil? %>
              <%# todo not like this %>
              <%
                valid_universes = []
                show_premium_notice = false

                # todo audit this
                if raw_model.is_a?(Character) || raw_model.is_a?(Location) || raw_model.is_a?(Item)
                  valid_universes += current_user.universes
                  valid_universes += current_user.contributable_universes
                else
                  # Premium content
                  if current_user.on_premium_plan? || (raw_model.persisted? && content.user == current_user)
                    valid_universes += current_user.universes
                  else
                    show_premium_notice = true
                  end

                  current_user.contributable_universes.each do |potential_universe|
                    if potential_universe.user.on_premium_plan?
                      valid_universes += [potential_universe]
                    end
                  end
                end
              %>

              <%= hidden_field_tag "#{raw_model.class.name.downcase}[custom_attribute_values][][name]", field[:id] %>
              <%=
                @universe_dropdown_options ||= valid_universes.uniq.sort_by(&:name).map { |u| [u.name, u.id] }
                select_tag "#{raw_model.class.name.downcase}[custom_attribute_values][][value]",
                  options_for_select(
                    @universe_dropdown_options.compact,
                    content.universe.try(:id)
                  ),
                  include_blank: current_user.on_premium_plan? || raw_model.is_a?(Character) || raw_model.is_a?(Location) || raw_model.is_a?(Item)
              %>
              <% if show_premium_notice %>
                <div class="help-text">
                  <i class="material-icons" style="font-size: 90%">info</i>
                  While on a <%= link_to 'Starter plan', subscription_path %>, you can only create premium content in universes you're a contributor to.
                </div>
              <% end %>
            <% else %>
              <br />
              <%= link_to(f.object.universe.name, f.object.universe) if f.object.universe %>
            <% end %>
          </div>
        </div>

      <% elsif field[:label].start_with?('Private') %>
        <%#<commit_msg>automatically add new content to scoped  universe<commit_after>
<%
  raw_model = content.is_a?(ContentSerializer) ? content.raw_model : content
%>

<div id="<%= category[:name].gsub("'", '') %>_panel" class="row panel" style="display: none">
  <% if category[:name] == 'gallery' %>
    <%= render partial: 'content/form/gallery/panel', locals: { f: f, content: content } %>
  <% end %>

  <% if category[:name] == 'contributors' %>
    <%# todo reorganize the files for all these panels? %>
    <%= render partial: 'content/form/contributors', locals: { f: f, content: content } %>
  <% end %>

  <% category[:fields].each do |field| %>
    <div class="col s12 m12 l12">
      <% if field[:type] == 'link' %>
        <%# Relation-setting UI %>
        <% through_class = raw_model.class.reflect_on_association(field[:old_column_source]).options[:through].to_s %>
        <%=
          render 'content/form/relation_input',
            f: f,
            attribute: field[:old_column_source],
            label: field[:label],
            relation: through_class
        %>

      <% elsif field[:type] == 'universe' %>
        <div class="content-field">
          <div class="input-field">
            <%= f.label field[:id], field[:label] %><br />

            <% if !f.object.persisted? || (f.object.persisted? && f.object.universe && f.object.universe.user == current_user) || f.object.universe_id.nil? %>
              <%# todo not like this %>
              <%
                valid_universes = []
                show_premium_notice = false

                # todo audit this
                if raw_model.is_a?(Character) || raw_model.is_a?(Location) || raw_model.is_a?(Item)
                  valid_universes += current_user.universes
                  valid_universes += current_user.contributable_universes
                else
                  # Premium content
                  if current_user.on_premium_plan? || (raw_model.persisted? && content.user == current_user)
                    valid_universes += current_user.universes
                  else
                    show_premium_notice = true
                  end

                  current_user.contributable_universes.each do |potential_universe|
                    if potential_universe.user.on_premium_plan?
                      valid_universes += [potential_universe]
                    end
                  end
                end
              %>

              <%= hidden_field_tag "#{raw_model.class.name.downcase}[custom_attribute_values][][name]", field[:id] %>
              <%=
                @universe_dropdown_options ||= valid_universes.uniq.sort_by(&:name).map { |u| [u.name, u.id] }
                select_tag "#{raw_model.class.name.downcase}[custom_attribute_values][][value]",
                  options_for_select(
                    @universe_dropdown_options.compact,
                    content.is_a?(ContentSerializer) ? content.universe.try(:id) : @universe_scope.try(:id)
                  ),
                  include_blank: current_user.on_premium_plan? || raw_model.is_a?(Character) || raw_model.is_a?(Location) || raw_model.is_a?(Item)
              %>
              <% if show_premium_notice %>
                <div class="help-text">
                  <i class="material-icons" style="font-size: 90%">info</i>
                  While on a <%= link_to 'Starter plan', subscription_path %>, you can only create premium content in universes you're a contributor to.
                </div>
              <% end %>
            <% else %>
              <br />
              <%= link_to(f.object.universe.name, f.object.universe) if f.object.universe %>
            <% end %>
          </div>
        </div>

      <% elsif field[:label].start_with?('Private') %>
        <%#
{'fraction_non_alphanumeric': 0.1379356568364611, 'fraction_numerical': 0.0021447721179624667, 'mean_word_length': 1.9076383476227592, 'pattern_counts': {'":': 0, '<': 85, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '915965', 'n_tokens_mistral': 2295, 'n_tokens_neox': 2116, 'n_words': 384}