<?php

return [
  [
    'name' => 'SavedSearch_Administer_Custom_Groups',
    'entity' => 'SavedSearch',
    'cleanup' => 'unused',
    'update' => 'unmodified',
    'replaces' => ['module' => 'civicrm_admin_ui'],
    'params' => [
      'version' => 4,
      'values' => [
        'name' => 'Administer_Custom_Groups',
        'label' => ts('Administer Custom Groups'),
        'api_entity' => 'CustomGroup',
        'api_params' => [
          'version' => 4,
          'select' => [
            'id',
            'title',
            'is_active',
            'extends:label',
            'extends_entity_column_value:label',
            'style:label',
            'is_reserved',
            'COUNT(CustomGroup_CustomField_custom_group_id_01.id) AS COUNT_CustomGroup_CustomField_custom_group_id_01_id',
            'GROUP_CONCAT(DISTINCT CustomGroup_CustomField_custom_group_id_01.label) AS GROUP_CONCAT_CustomGroup_CustomField_custom_group_id_01_label',
          ],
          'orderBy' => [],
          'where' => [
            [
              'is_reserved',
              '=',
              FALSE,
            ],
          ],
          'groupBy' => [
            'id',
          ],
          'join' => [
            [
              'CustomField AS CustomGroup_CustomField_custom_group_id_01',
              'LEFT',
              [
                'id',
                '=',
                'CustomGroup_CustomField_custom_group_id_01.custom_group_id',
              ],
            ],
          ],
          'having' => [],
        ],
      ],
      'match' => [
        'name',
      ],
    ],
  ],
  [
    'name' => 'SavedSearch_Administer_Custom_Groups_SearchDisplay_Table',
    'entity' => 'SearchDisplay',
    'cleanup' => 'unused',
    'update' => 'unmodified',
    'replaces' => ['module' => 'civicrm_admin_ui'],
    'params' => [
      'version' => 4,
      'values' => [
        'name' => 'Table',
        'label' => ts('Table'),
        'saved_search_id.name' => 'Administer_Custom_Groups',
        'type' => 'table',
        'settings' => [
          'actions' => TRUE,
          'limit' => 50,
          'classes' => [
            'table',
            'table-striped',
            'crm-sticky-header',
          ],
          'pager' => [
            'show_count' => TRUE,
            'expose_limit' => TRUE,
            'hide_single' => TRUE,
          ],
          'sort' => [],
          'columns' => [
            [
              'type' => 'field',
              'key' => 'id',
              'label' => ts('ID'),
              'sortable' => TRUE,
            ],
            [
              'type' => 'field',
              'key' => 'title',
              'label' => ts('Group Title'),
              'sortable' => TRUE,
            ],
            [
              'type' => 'field',
              'key' => 'extends:label',
              'label' => ts('Used For'),
              'sortable' => TRUE,
              'rewrite' => '[extends:label]',
            ],
            [
              'type' => 'field',
              'key' => 'extends_entity_column_value:label',
              'label' => ts('Subtypes'),
              'sortable' => TRUE,
            ],
            [
              'type' => 'field',
              'key' => 'is_active',
              'label' => ts('Enabled'),
              'sortable' => TRUE,
              'editable' => TRUE,
            ],
            [
              'type' => 'field',
              'key' => 'style:label',
              'label' => ts('Style'),
              'sortable' => TRUE,
            ],
            [
              'type' => 'html',
              'key' => 'GROUP_CONCAT_CustomGroup_CustomField_custom_group_id_01_label',
              'label' => ts('Fields'),
              'sortable' => TRUE,
              'rewrite' => "{capture assign=fields}[GROUP_CONCAT_CustomGroup_CustomField_custom_group_id_01_label]{/capture}{\$fields|replace:',':'<br>'}",
            ],
            [
              'size' => 'btn-xs',
              'links' => [
                [
                  'entity' => '',
                  'action' => '',
                  'join' => '',
                  'target' => '',
                  'icon' => 'fa-list-alt',
                  'text' => ts('Fields (%1)', [1 => '[COUNT_CustomGroup_CustomField_custom_group_id_01_id]']),
                  'style' => 'default',
                  'path' => 'civicrm/admin/custom/group/fields#/?gid=[id]',
                  'condition' => [],
                  'task' => '',
                ],
                [
                  'entity' => 'CustomGroup',
                  'action' => 'update',
                  'join' => '',
                  'target' => 'crm-popup',
                  'icon' => 'fa-pencil',
                  'text' => ts('Settings'),
                  'style' => 'default',
                  'path' => '',
                  'condition' => [],
                  'task' => '',
                ],
              ],
              'type' => 'buttons',
              'alignment' => 'text-right',
            ],
            [
              'text' => '',
              'style' => 'default',
              'size' => 'btn-xs',
              'icon' => 'fa-bars',
              'links' => [
                [
                  'entity' => 'CustomGroup',
                  'action' => 'preview',
                  'join' => '',
                  'target' => 'crm-popup',
                  'icon' => 'fa-eye',
                  'text' => ts('Preview'),
                  'style' => 'default',
                  'path' => '',
                  'condition' => [],
                  'task' => '',
                ],
                [
                  'task' => 'enable',
                  'entity' => 'CustomGroup',
                  'target' => 'crm-popup',
                  'icon' => 'fa-toggle-on',
                  'text' => ts('Enable'),
                  'style' => 'default',
                  'condition' => [],
                  'path' => '',
                  'action' => '',
                  'join' => '',
                ],
                [
                  'task' => 'disable',
                  'entity' => 'CustomGroup',
                  'target' => 'crm-popup',
                  'icon' => 'fa-toggle-off',
                  'text' => ts('Disable'),
                  'style' => 'default',
                  'condition' => [],
                  'path' => '',
                  'action' => '',
                  'join' => '',
                ],
                [
                  'entity' => 'CustomGroup',
                  'action' => 'delete',
                  'join' => '',
                  'target' => 'crm-popup',
                  'icon' => 'fa-trash',
                  'text' => ts('Delete'),
                  'style' => 'danger',
                  'path' => '',
                  'condition' => [],
                  'task' => '',
                ],
                [
                  'entity' => 'CustomField',
                  'action' => 'add',
                  'join' => 'CustomGroup_CustomField_custom_group_id_01',
                  'target' => 'crm-popup',
                  'style' => 'default',
                  'text' => ts('Add Custom Field'),
                  'icon' => 'fa-plus',
                  'path' => '',
                  'task' => '',
                  'condition' => [],
                ],
              ],
              'type' => 'menu',
              'alignment' => 'text-right',
            ],
          ],
          'draggable' => 'weight',
          'cssRules' => [
            [
              'disabled',
              'is_active',
              '=',
              FALSE,
            ],
          ],
          'placeholder' => 5,
          'toolbar' => [
            [
              'entity' => 'CustomGroup',
              'action' => 'add',
              'target' => 'crm-popup',
              'style' => 'primary',
              'text' => ts('Add Set of Custom Fields'),
              'icon' => 'fa-plus',
              'autoOpen' => TRUE,
              'path' => '',
              'task' => '',
              'join' => '',
              'condition' => [],
            ],
          ],
        ],
      ],
      'match' => [
        'saved_search_id',
        'name',
      ],
    ],
  ],
];
