require_relative "../../lib/offline_template.rb"

def self.create_pages_seed_tree items, parent = nil
  @parent ||= parent
  items.each do |item|
    if item.kind_of?(Array)
      create_pages_seed_tree item, @parent
    else
      item[:parent] = parent
      item[:kind] = :external if item[:external_url]
      item[:kind] = :extension if item[:extension]
      item[:kind] = :shortcut if item[:page_id]
      item[:hidden] = item[:hidden] if item[:hidden]

      @parent = Patchwork::Page.find_or_create_by(item)
    end
  end
end


create_pages_seed_tree [
                           {
                               title: "www.example.com",
                               page_id: 2,
                           }, [
                               {
                                   title: "Home",
                                   body: OfflineTemplate.new.render("statics/pages/home", layout: false),
                                   identifier: "landing"
                               },
                               {
                                   title: "Generic",
                                   body: OfflineTemplate.new.render("statics/pages/generic", layout: false),
                               },
                               {
                                   title: "Elements",
                                   body: OfflineTemplate.new.render("statics/pages/elements", layout: false),
                               }
                           ]
                       ]
