Rails.application.routes.draw do

  locales = Site.first.in_use_locales rescue I18n.available_locales
  
  scope "(:locale)", locale: Regexp.new(locales.join("|")) do
   namespace :admin do
      post 'custom_announcement/preview', to: 'custom_announcements#preview'
      post 'custom_announcement/createfeed', to: 'custom_announcements#createfeed'
      post 'custom_announcement/importcustom_anns', to: 'custom_announcements#importcustom_anns'
      post 'custom_announcement/import_from_xml', to: 'custom_announcements#import_from_xml'
      get 'custom_announcement/excel_format', to: 'custom_announcements#excel_format'
      get 'custom_announcement/export_excel', to: 'custom_announcements#export_excel'
      patch 'custom_announcement/updatefeed', to: 'custom_announcements#updatefeed'
      delete 'custom_announcement/deletefeed', to: 'custom_announcements#deletefeed'
      get 'custom_announcement/destroy_preview/:slug_title-:uid', to: 'custom_announcements#destroy_preview'
      post 'custom_announcement/approve_custom_bulletin', to: 'custom_announcements#approve_custom_bulletin'
      get 'custom_announcement/feed', to: 'custom_announcements#feed'
      get 'custom_announcements/feedform', to: 'custom_announcements#feedform'
      get 'custom_announcement/settings', to: 'custom_announcements#settings'
      get 'custom_announcement/import', to: 'custom_announcements#import'
      post 'custom_announcement/createsettings', to: 'custom_announcements#createsettings'
      patch 'custom_announcement/updatesettings', to: 'custom_announcements#updatesettings'
      post 'custom_announcement/import_from_wp', to: 'custom_announcements#import_from_wp'
      post 'custom_announcement/generate_iframe_url' => 'custom_announcements#generate_iframe_url'
      resources :custom_announcements do
        collection do
          get "/:custom_module-:bind_uid" => "custom_announcements#index"
          get "/:custom_module-:bind_uid/new" => "custom_announcements#new"
          get "/:custom_module-:bind_uid/:id/edit" => "custom_announcements#edit"
          delete "/:custom_module-:bind_uid/:id/destroy" => "custom_announcements#destroy"
          get '/:custom_module-:bind_uid/:id/comment'=> 'custom_announcements#comment'

          get "/:custom_module" => "custom_announcements#index"
          get "/:custom_module/new" => "custom_announcements#new"
          get "/:custom_module/:id/edit" => "custom_announcements#edit"
          delete "/:custom_module/:id/destroy" => "custom_announcements#destroy"
          get '/:custom_module/:id/comment'=> 'custom_announcements#comment'
        end
      end
      get 'custom_announcements/:id/comment'=> 'custom_announcements#comment'
      get 'annc-comment-hidden/:id' => 'custom_announcements#comment_hidden'
   end

   resources :custom_announcements do
    collection do
      get ':slug_title-:uid', to: 'custom_announcements#show', as: :display
    end
   end

   get "/xhr/custom_announcements/feed/:uid" => "custom_announcement_feeds#feed"
   get "/xhr/custom_announcements/rssfeed/:uid" => "custom_announcement_feeds#rssfeed"
   get "/xhr/custom_announcements/feeds" => "custom_announcement_feeds#feeds"
   get '/xhr/custom_announcements/custom_announcement.json', to: 'custom_bulletins#get_custom_bulletins'
   get '/xhr/panel/custom_announcement/widget/sync_data' => 'custom_announcements#show_widget'
   get '/xhr/custom_announcements/:slug_title-:uid/comment', to: 'custom_announcements#comment' 
   get '/xhr/custom_announcements/file/:id/*f_name' => 'custom_announcements#get_file'
  end
  
end
