module Turbo::FramesHelper

def turbo_frame_tag(*ids, src: nil, target: nil, **attributes, &block)

# =>
<%= turbo_frame_tag(Article.find(1), Comment.new) %>

# =>
<%= turbo_frame_tag(Article.find(1), "comments") %>

# =>
<%= turbo_frame_tag(Article.find(1)) %>

`dom_id` if applicable to easily generate unique ids for Turbo Frames:
The `turbo_frame_tag` helper will convert the arguments it receives to their

# =>
My tray frame!

<% end %>
My tray frame!

<%= turbo_frame_tag "tray" do %>

# =>
<%= turbo_frame_tag "tray", src: tray_path(tray), loading: "lazy" %>

# =>
<%= turbo_frame_tag "tray", target: "other_tray" %>

# =>
<%= turbo_frame_tag "tray", src: tray_path(tray), target: "_top" %>

# =>
<%= turbo_frame_tag tray, src: tray_path(tray) %>

# =>
<%= turbo_frame_tag "tray", src: tray_path(tray) %>

=== Examples

fetches the URL supplied in the +src+ attribute.
Returns a frame tag that can either be used simply to encapsulate frame content or as a lazy-loading container that starts empty but
def turbo_frame_tag(*ids, src: nil, target: nil, **attributes, &block)
  id = ids.map { |id| id.respond_to?(:to_key) ? ActionView::RecordIdentifier.dom_id(id) : id }.join("_")
  src = url_for(src) if src.present?
  tag.turbo_frame(**attributes.merge(id: id, src: src, target: target).compact, &block)
end