# -*- encoding : utf-8 -*-
class Public::MenuItemsController < ApplicationController
  
  layout "public"
  
  def redirect
    redirect_to menu_item_path(:url => params[:url]), status: 301
  end
  
  def archive
    @menu_item= MenuItem.archived.find(params[:id])
  end
  
  
  def show
    
    if params[:lang]
      
      @lang = LangSite.find_by_slug(params[:lang])
    else
      @lang = LangSite.last
      
    end
    
    
    if params[:url]
      
      url = params[:url].split("/")
      url = url.map do |u|
        u.to_slug
      end
      url = url.join("/")
      
      orignal_url = url
      
      if url.scan(/peuples\-sauvages\/experimentes/).size > 0
        url = url.gsub(/peuples\-sauvages\/experimentes/, 'compagnons-animaux/experimentes') 
        @original_menu_item = MenuItem.find(19)
      end  
      if url.scan(/animaux\-domestiques\/experimentes/).size > 0
        url = url.gsub(/animaux\-domestiques\/experimentes/, 'compagnons-animaux/experimentes') 
        @original_menu_item = MenuItem.find(20)
      end  
        
      
      
      
      
      @menu_item_lang = @lang.menu_item_langs.find_by_permalink(url)
      
      if @menu_item_lang
        @menu_item = @menu_item_lang.menu_item
      
        @menu_item.ancestors_menu = @menu_item.ancestors
        @ancestor_1 = @menu_item.ancestors.reverse[1] if @menu_item
      else
        redirect_to "/"
      end
      

      
    else
    
      @menu_item_lang = @lang.menu_item_langs.find_by_permalink("index")
      @menu_item = @menu_item_lang.menu_item
    
    
    end
    if @menu_item and @menu_item.menu_content and @menu_item.menu_content.class.to_s == "Page"
      @lang_page = @menu_item.menu_content.lang_pages.find_by_lang_site_id(@lang.id)
      @title = @lang_page.title
      @description = @lang_page.description
      @keywords = @lang_page.keywords

    end
   #puts @menu_item.menu_item_langs.find_by_lang_site_id(@lang.id)
  
    
    end

end
