-- Migration: Add filter-select-search to Cases module
-- Date: 2025-10-01

UPDATE modules
SET config = '{
  "title": "Cases",
  "header": [
    {
      "type": "filter-select",
      "options": {
        "source_table": "cases",
        "source_column": "case_id",
        "display_column": "title",
        "data_column": "title",
        "data_column_id": "selected_case_id",
        "placeholder": "Search cases by client, number, or title...",
        "search_fields": ["client_name", "case_number", "title"],
        "max_results": 25,
        "debounce_ms": 250,
        "populateMode": "immediate"
      }
    },
    {
      "type": "button",
      "label": "Add Case",
      "formName": "Case"
    },
    {
      "type": "button",
      "label": "Detail View",
      "onClick": "openSelectedDetail"
    }
  ],
  "body": [
    {
      "type": "table",
      "options": {
        "tableName": "cases",
        "showGlobalSearch": false,
        "addButton": false,
        "rowClick": "selectRecord",
        "columnsToShow": ["client_name", "case_number", "title", "lead_rep_name", "added_by"],
        "filterField": "title",
        "listenColumn": "title"
      }
    }
  ],
  "footer": [
    {
      "type": "button",
      "label": "Close",
      "onClick": "closeModal"
    }
  ]
}'::jsonb
WHERE name = 'Cases';
