# -*- coding: utf-8 -*-
# Configures your navigation
module SimpleNavigationn
  module Renderer
    class BootstrapBreadcrumbs < SimpleNavigation::Renderer::Base
      def render(item_container)
        content_tag(:ul, li_tags(item_container).join(join_with), id: item_container.dom_id, class: "page-breadcrumb breadcrumb")
      end

      protected

      def li_tags(item_container)
        item_container.items.inject([]) do |list, item|
          # rubocop:disable Style/IfInsideElse
          if item.selected?
            if include_sub_navigation?(item)
              list << content_tag(:li, link_to(item.name[:text], item.url, { method: item.method }.merge(item.html_options.except(:class, :id)))) if item.selected?
              list.concat li_tags(item.sub_navigation)
            elsif item.name.is_a? String
              list << content_tag(:li, item.name, class: 'active ') if item.selected?
            else
              list << content_tag(:li, item.name[:text], class: 'active ') if item.selected?
            end
          else
            next
          end
          # rubocop:enable Style/IfInsideElse
        end
        list
      end
    end

    def join_with
      @join_with ||= options[:join_with] || ' <i class="fa fa-circle"></i> '
      content_tag(:li, content_tag(:span, @join_with, class: 'divider'))
    end
  end
end
SimpleNavigation.register_renderer bootstrap_breadcrumbs: SimpleNavigationn::Renderer::BootstrapBreadcrumbs
# rubocop:disable Metrics/BlockLength
SimpleNavigation::Configuration.run do |navigation|
  navigation.renderer = SimpleNavigationRenderers::Bootstrap3
  navigation.items do |primary|
    if current_user.usertype == 'A'
      # clientes
      primary.item :customers, { icon: "fa fa-fw fa-smile-o", text: "Clientes" }, customers_path, class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
        sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
        sub_nav.item :new_customer, 'Nuevo Cliente', new_customer_path
        sub_nav.item :list_customers, 'Lista de clientes', customers_path
        sub_nav.item :divider_after_list_customers, '#', divider: true
        sub_nav.item :special_prices, 'Descuentos especiales por cliente', new_special_price_path
      end
      # proveedores
      primary.item :suppliers, { icon: "fa fa-fw fa-suitcase", text: "Proveedores" }, suppliers_path, class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
        sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
        sub_nav.item :new_supplier, 'Nuevo Proveedor', new_supplier_path
        sub_nav.item :list_suppliers, 'Lista de proveedores', suppliers_path
      end
      # productos
      primary.item :products, { icon: "fa fa-fw fa-cubes", text: "Productos" }, products_path, class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
        sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
        sub_nav.item :units, 'Unidades de medida', units_path
        sub_nav.item :divider_before_categories, '#', divider: true
        sub_nav.item :new_category, 'Nueva línea de producto', new_category_path
        sub_nav.item :list_categories, 'Lista de líneas de producto', categories_path
        sub_nav.item :divider_before_products, '#', divider: true
        sub_nav.item :new_product, 'Nuevo Producto', new_product_path
        sub_nav.item :list_products, 'Lista de productos', products_path
        sub_nav.item :stock_by_pointsale, 'Existencias', stock_by_pointsale_path
        sub_nav.item :list_waste_of_products, 'Lista de mermas de productos', product_wastes_path
        sub_nav.item :divider_before_purchases, '#', divider: true
        sub_nav.item :new_product, 'Nueva Compra', new_purchase_path
        sub_nav.item :list_products, 'Lista de compras', purchases_path
        sub_nav.item :divider_before_purchases, '#', divider: true
        sub_nav.item :product_track, 'Seguimiento de productos', product_track_path
      end
      # puntos de venta y caja registradora
      primary.item :pointsales, { icon: "fa fa-fw fa-cart-plus", text: "Puntos de venta" }, pointsales_path, class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
        sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
        sub_nav.item :new_pointsale, 'Nuevo Punto de venta', new_pointsale_path
        sub_nav.item :list_pointsales, 'Lista de puntos de venta', pointsales_path
        sub_nav.item :divider_before_pointsales, '#', divider: true
        sub_nav.item :list_cash_registers, 'Lista de cajas', cash_registers_path
        sub_nav.item :list_cash_outs, 'Lista de cortes de caja', cash_outs_path
        sub_nav.item :divider_before_sellers, '#', divider: true
        sub_nav.item :new_seller, 'Nuevo vendedor', new_seller_path
        sub_nav.item :list_sellers, 'Lista de vendedores', sellers_path
        sub_nav.item :divider_after_sellers, '#', divider: true
        sub_nav.item :new_transfer, 'Nuevo traspaso', new_transfer_path
        sub_nav.item :list_transfers, 'Lista de traspasos', transfers_path
        sub_nav.item :divider_after_list_users, '#', divider: true
        sub_nav.item :list_warehouse, 'Almacenes', warehouses_path
      end
      # ventas
      primary.item :sales, { icon: "fa fa-fw fa-money", text: "Ventas" }, sales_path, class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
        sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
        sub_nav.item :list_sales, 'Lista de ventas', sales_path
        sub_nav.item :divider_after_list_sales, '#', divider: true
        sub_nav.item :list_sales_reserved, 'Lista de apartados', sales_reserved_path
        sub_nav.item :commission, "Lista de comisiones", commissions_path
      end
      # egresos
      primary.item :expensesconcepts, { icon: "fa fa-fw fa-dollar", text: "Egresos" }, expensesconcepts_path, class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
        sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
        sub_nav.item :new_expensesconcept, 'Nuevo Concepto de egreso', new_expensesconcept_path
        sub_nav.item :list_expensesconcepts, 'Lista de conceptos de egreso', expensesconcepts_path
        sub_nav.item :divider_after_list_expensesconcepts, '#', divider: true
        sub_nav.item :new_expense, 'Nuevo egreso', new_expense_path
        sub_nav.item :list_expenses, 'Lista de egresos', expenses_path
      end
      # reportes
      primary.item :reports, { icon: "fa fa-bar-chart", text: "Reportes" }, '#', class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
        sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
        sub_nav.item :sales_per_month, 'Ventas por mes', sales_per_month_report_path
      end
      # configuracion
      primary.item :config, { icon: "fa fa-fw fa-cog", text: "Configuración" }, '#', class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
        sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
        sub_nav.item :pos_configs, 'Configurar parámetros generales', pos_configs_path
        sub_nav.item :divider_after_list_transfers, '#', divider: true
        sub_nav.item :list_users, 'Usuarios del sistema', users_path
      end
    end

    if current_user.usertype == 'G'
      primary.item :home, { icon: "fa fa-fw fa-home", text: "Inicio" }, root_path, class: 'menu-dropdown classic-menu-dropdown'
      # clientes
      primary.item :customers, { icon: "fa fa-fw fa-smile-o", text: "Clientes" }, customers_path, class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
        sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
        sub_nav.item :new_customer, 'Nuevo Cliente', new_customer_path
        sub_nav.item :list_customers, 'Lista de clientes', customers_path
        sub_nav.item :debtor_customers, 'Clientes deudores', debtors_path
      end
      # proveedores
      primary.item :suppliers, { icon: "fa fa-fw fa-suitcase", text: "Proveedores" }, suppliers_path, class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
        sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
        sub_nav.item :new_supplier, 'Nuevo Proveedor', new_supplier_path
        sub_nav.item :list_suppliers, 'Lista de proveedores', suppliers_path
      end
      # productos
      primary.item :products, { icon: "fa fa-fw fa-cubes", text: "Productos" }, products_path, class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
        sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
        sub_nav.item :units, 'Unidades de medida', units_path
        sub_nav.item :divider_before_categories, '#', divider: true
        sub_nav.item :new_category, 'Nueva línea de producto', new_category_path
        sub_nav.item :list_categories, 'Lista de líneas de producto', categories_path
        sub_nav.item :divider_before_products, '#', divider: true
        sub_nav.item :new_product, 'Nuevo Producto', new_product_path
        sub_nav.item :list_products, 'Lista de productos', products_path
        sub_nav.item :divider_after_list_products, '#', divider: true
        sub_nav.item :stock_by_pointsale, 'Existencias', stock_by_pointsale_path
        sub_nav.item :divider_after_stock_by_pointsale, '#', divider: true
        sub_nav.item :list_waste, 'Nueva merma de productos', new_product_waste_path
        sub_nav.item :list_waste_of_products, 'Lista de mermas de productos', product_wastes_path
        sub_nav.item :divider_before_purchases, '#', divider: true
        sub_nav.item :new_purchase, 'Nueva Compra', new_purchase_path
        sub_nav.item :purchases_list, 'Lista de compras', purchases_path
      end
      # ventas
      primary.item :sales, { icon: "fa fa-fw fa-money", text: "Ventas" }, sales_path, class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
        sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
        sub_nav.item :new_sale, 'Nueva venta', new_sale_path
        sub_nav.item :list_sales, 'Lista de ventas', sales_path
        sub_nav.item :divider_after_list_sales, '#', divider: true
        sub_nav.item :list_sales_reserved, 'Lista de apartados', sales_reserved_path
        sub_nav.item :divider_after_list_sales_reserved, '#', divider: true
        sub_nav.item :commission, "Lista de comisiones", commissions_path
        sub_nav.item :divider_after_list_comissions, '#', divider: true
        sub_nav.item :list_products_return, 'Lista de devoluciones', products_returns_path
      end
      # punto de venta, caja registradora y vendedores
      primary.item :pointsales, { icon: "fa fa-fw fa-cart-plus", text: "Puntos de venta" }, pointsales_path, class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
        sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
        sub_nav.item :new_product, 'Nueva Caja', new_cash_register_path
        sub_nav.item :list_products, 'Lista de cajas ', cash_registers_path
        sub_nav.item :divider_after_list_products, '#', divider: true
        sub_nav.item :list_cash_outs, 'Lista de cortes de caja', cash_outs_path
        sub_nav.item :divider_after_list_cash_outs, '#', divider: true
        sub_nav.item :new_seller, 'Nuevo vendedor', new_seller_path
        sub_nav.item :list_sellers, 'Lista de vendedores', sellers_path
        sub_nav.item :divider_after_list_sellers, '#', divider: true
        sub_nav.item :new_transfer, 'Nuevo traspaso', new_transfer_path
        sub_nav.item :list_transfers, 'Lista de traspasos', transfers_path
        sub_nav.item :divider_after_list_transfers, '#', divider: true
        sub_nav.item :list_warehouse, 'Almacenes', warehouses_path
      end
      # coneptos de egresos
      primary.item :expensesconcepts, { icon: "fa fa-fw fa-dollar", text: "Egresos" }, expensesconcepts_path, class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
        sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
        sub_nav.item :new_expensesconcept, 'Nuevo egreso', new_expense_path
        sub_nav.item :list_expensesconcepts, 'Lista de egresos', expenses_path
        sub_nav.item :divider_after_expenses, '#', divider: true
        sub_nav.item :list_expensesconcepts, 'Lista de conceptos de egreso', expensesconcepts_path
      end
      # configuracion
      primary.item :config, { icon: "fa fa-fw fa-cog", text: "Configuración" }, '#', class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
        sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
        sub_nav.item :list_products_initial_stock, 'Stock inicial de productos', products_initial_stock_path(current_user.pointsale_id)
        sub_nav.item :list_products_stock, 'Stock mínimo y máximo de productos', products_stock_path(current_user.pointsale_id)
        sub_nav.item :divider_after_list_transfers, '#', divider: true
        sub_nav.item :list_users, 'Usuarios del sistema', users_path
      end
    end

    if current_user.usertype == 'C'
      primary.item :home, { icon: "fa fa-fw fa-home", text: "Inicio" }, root_path, class: 'menu-dropdown classic-menu-dropdown'
      # clientes
      primary.item :customers, { icon: "fa fa-fw fa-smile-o", text: "Clientes" }, customers_path, class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
        sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
        sub_nav.item :new_customer, 'Nuevo Cliente', new_customer_path
        sub_nav.item :list_customers, 'Lista de clientes', customers_path
        sub_nav.item :divider_after_list_customers, '#', divider: true
        sub_nav.item :debtor_customers, 'Clientes deudores', debtors_path
      end

      # productos
      primary.item :products, { icon: "fa fa-fw fa-cubes", text: "Productos" }, products_path, class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
        sub_nav.item :stock_by_pointsale, 'Existencias', stock_by_pointsale_path
        sub_nav.item :divider_after_stock_by_pointsale, '#', divider: true
        sub_nav.item :list_waste, 'Nueva merma de productos', new_product_waste_path
        sub_nav.item :list_waste_of_products, 'Lista de mermas de productos', product_wastes_path
      end
      # ventas
      primary.item :sales, { icon: "fa fa-fw fa-money", text: "Ventas" }, sales_path, class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
        sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
        sub_nav.item :new_sale, 'Nueva venta', new_sale_path
        sub_nav.item :list_sales, 'Lista de ventas', sales_path
        sub_nav.item :divider_after_list_sales, '#', divider: true
        sub_nav.item :list_sales_reserved, 'Lista de apartados', sales_reserved_path
        sub_nav.item :divider_after_list_comissions, '#', divider: true
        sub_nav.item :list_products_return, 'Lista de devoluciones', products_returns_path
      end
      # caja y cortes de caja
      primary.item :cash_register, { icon: "fa fa-shopping-cart", text: "Caja" }, '#', class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
        sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
        sub_nav.item :cash_out, 'Corte de caja', new_cash_out_path
        # sub_nav.item :list_cash_outs, 'Lista de cortes de caja', cash_outs_path
      end
      # conceptos de egresos
      primary.item :expenses, { icon: "fa fa-fw fa-dollar", text: "Egresos" }, expenses_path, class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
        sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
        sub_nav.item :new_expense, 'Nuevo egreso', new_expense_path
        sub_nav.item :list_expenses, 'Lista de egresos', expenses_path
      end
      # conceptos de egresos
      primary.item :transfers, { icon: "fa fa-fw fa-dollar", text: "Traspasos" }, transfers_path, class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
        sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
        sub_nav.item :new_transfer, 'Nuevo traspaso', new_transfer_path
        sub_nav.item :list_expenses, 'Lista de traspasos', transfers_path
      end
    end

    if current_user.usertype == 'S'
      primary.item :home, { icon: "fa fa-fw fa-home", text: "Inicio" }, root_path, class: 'menu-dropdown classic-menu-dropdown'
      # existencias
      primary.item :products, { icon: "fa fa-fw fa-cubes", text: "Existencias" }, stock_by_pointsale_path, class: 'menu-dropdown classic-menu-dropdown'
      # traspasos
      primary.item :transfers, { icon: "fa fa-fw fa-exchange", text: "Traspasos" }, '#', class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
        sub_nav.item :new_transfer, 'Nuevo traspaso', new_transfer_path
        sub_nav.item :list_transfers, 'Lista de traspasos', transfers_path
      end
      # mermas
      primary.item :product_wastes, { icon: "fa fa-fw fa-arrow-down", text: "Mermas" }, '#', class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
        sub_nav.item :list_waste, 'Nueva merma de productos', new_product_waste_path
        sub_nav.item :list_waste_of_products, 'Lista de mermas de productos', product_wastes_path
      end
      # inventario
      primary.item :stock, { icon: "fa fa-fw fa-database", text: "Inventario" }, '#', class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
        sub_nav.item :initial_stock, 'Inventario inicial', products_initial_stock_path(current_user.warehouse_id)
        sub_nav.item :stock_adjustment, 'Ajuste de inventario', products_stock_path(current_user.warehouse_id)
      end
    end

    class BootstrapBreadcrumbs < SimpleNavigation::Renderer::Base
      def render(item_container)
        content_tag(:ul, li_tags(item_container).join(join_with), id: item_container.dom_id, class: "#{item_container.dom_class} breadcrumb")
      end

      protected

      def li_tags(item_container)
        item_container.items.inject([]) do |list, item|
          # rubocop:disable Style/IfInsideElse
          if item.selected?
            if include_sub_navigation?(item)
              list << content_tag(:li, link_to(item.name, item.url, { method: item.method }.merge(item.html_options.except(:class, :id)))) if item.selected?
              list.concat li_tags(item.sub_navigation)
            else
              list << content_tag(:li, item.name, class: 'active') if item.selected?
            end
          end
          # rubocop:enable Style/IfInsideElse
          list
        end
      end

      def join_with
        @join_with ||= options[:join_with] || '<span class="divider">/</span>'.html_safe
      end
    end
  end
end
# rubocop:enable Metrics/BlockLength
