-- Migration: Fix Products Module Search Configuration
-- Date: 2025-11-13
-- Description: Updates the products module configuration to fix search functionality
-- This migration updates the filter-select configuration and enables proper partial search

-- Update the products module configuration
UPDATE modules 
SET config = '{
  "title": "Products",
  "header": [
    {
      "type": "filter-select",
      "options": {
        "source_table": "products",
        "source_column": "name",
        "display_column": "name",
        "data_column": "name",
        "data_column_id": "selected_product_id",
        "placeholder": "Search products by name...",
        "search_fields": ["name", "brand", "sku", "product_number"],
        "max_results": 25,
        "debounce_ms": 250,
        "populateMode": "immediate"
      }
    },
    {
      "type": "button",
      "label": "Add Product",
      "formName": "Product"
    },
    {
      "type": "button",
      "label": "Auto Orders",
      "formName": "Auto Order"
    },
    {
      "type": "button",
      "label": "Generate Barcode",
      "action": "products:generate-barcode"
    },
    {
      "type": "button",
      "label": "Generate QR Code",
      "action": "products:generate-qrcode"
    },
    {
      "type": "button",
      "label": "Import Products",
      "onClick": "importProducts",
      "class": "btn-outline btn-info"
    },
    {
      "type": "button",
      "label": "Export Products",
      "onClick": "exportProducts",
      "class": "btn-outline btn-success"
    }
  ],
  "body": [
    {
      "type": "tabs",
      "tabs": [
        {
          "label": "Products",
          "elements": [
            {
              "type": "table",
              "options": {
                "tableName": "products",
                "showGlobalSearch": true,
                "addButton": false,
                "editFormId": 111,
                "filterField": "name",
                "listenColumn": "name",
                "limit": 1000,
                "columns": [
                  {
                    "field": "name",
                    "label": "Name"
                  },
                  {
                    "field": "price",
                    "label": "Price"
                  },
                  {
                    "field": "brand",
                    "label": "Brand"
                  },
                  {
                    "field": "tax_rates",
                    "label": "Tax Rates",
                    "renderer": "json",
                    "rendererOptions": {
                      "maxInlineItems": 3
                    }
                  }
                ],
                "rowActions": [
                  {
                    "label": "Discount",
                    "formId": 150,
                    "icon": "fa-tags",
                    "class": "btn-sm btn-info"
                  }
                ]
              }
            }
          ]
        },
        {
          "label": "Auto Orders",
          "elements": [
            {
              "type": "table",
              "options": {
                "tableName": "auto_orders",
                "showGlobalSearch": false,
                "addButton": false,
                "editFormId": 131,
                "limit": 1000,
                "columnsToShow": [
                  "product_name",
                  "minimum_stock_qty",
                  "order_qty"
                ]
              }
            }
          ]
        }
      ]
    }
  ],
  "footer": [
    {
      "type": "button",
      "label": "Close",
      "onClick": "closeModal"
    }
  ]
}'::json
WHERE name = 'Products';
