module Patchwork
  module Admin
    class PagesController < Patchwork::Admin::ApplicationController
      include Patchwork::Mixin::Controller::SortableController

      def index
        search_term = params[:search].to_s.strip
        resources = Patchwork::Admin::Search.new(resource_resolver, search_term).run
        resources = order.apply(resources)
        render locals: {
          resources: resources.nested_set.all,
          page: Patchwork::Admin::Page::Collection.new(dashboard, order: order),
        }
      end

      def fedit
        render locals: {
            page: Patchwork::Liquid::Helpers::Base.liquidize(Patchwork::Page.find(params[:id]).body)
        }, layout: "patchwork/admin/fedit"
      end
    end
  end
end
