<commit_before><?php
namespace Pulsestorm\Magento2\Cli\Magento2_Generate_Ui_Grid;
use function Pulsestorm\Pestle\Importer\pestle_import;
pestle_import('Pulsestorm\Pestle\Library\output');
pestle_import('Pulsestorm\Pestle\Library\exitWithErrorMessage');
pestle_import('Pulsestorm\Xml_Library\simpleXmlAddNodesXpath');    
pestle_import('Pulsestorm\Xml_Library\formatXmlString');
pestle_import('Pulsestorm\Xml_Library\getXmlNamespaceFromPrefix');
pestle_import('Pulsestorm\Magento2\Cli\Xml_Template\getBlankXml');
pestle_import('Pulsestorm\Magento2\Cli\Library\getModuleInformation');
pestle_import('Pulsestorm\Pestle\Library\writeStringToFile');
pestle_import('Pulsestorm\Magento2\Cli\Library\createClassFile');
pestle_import('Pulsestorm\Cli\Code_Generation\createClassTemplateWithUse');
pestle_import('Pulsestorm\Magento2\Cli\Library\addArgument');
pestle_import('Pulsestorm\Magento2\Cli\Library\addItem');
function generateArgumentNode($xml, $gridId, $dataSourceName, $columnsName, $collection)
{
    $shortName = getShortModelNameFromResourceModelCollection(
        $collection);    
    $fullIdentifier = $gridId . '.' . $dataSourceName;
    
    $argument   = addArgument($xml, 'data', 'array');
    $js_config  = addItem($argument,'js_config','array');
    $provider   = addItem($js_config, 'provider', 'string', $fullIdentifier);      
    $deps       = addItem($js_config, 'deps', 'string', $fullIdentifier);      
    $spinner    = addItem($argument, 'spinner', 'string', $columnsName);         
    
    $buttons    = addItem($argument, 'buttons', 'array');
    $add        = addItem($buttons, 'add', 'array');
    addItem($add, 'name', 'string', 'add');
    addItem($add, 'label', 'string', 'Add New');
    addItem($add, 'class', 'string', 'primary');
    addItem($add, 'url', 'string', '*/'.$shortName.'/new');

    return $argument;
}

function addArgumentsToDataProvider($dataProvider, $providerClass, 
            $dataSourceName, $databaseIdName, $requestIdName)
{
    addArgument($dataProvider, 'class','string',$providerClass);
    addArgument($dataProvider, 'name','string',$dataSourceName);
    addArgument($dataProvider, 'primaryFieldName','string',$databaseIdName);
    addArgument($dataProvider, 'requestFieldName','string',$requestIdName);
    $dataForProvider = addArgument($dataProvider, 'data','array');
    
    $config     = addItem($dataForProvider, 'config','array');
    $update_url = addItem($config,'update_url','url');
    $update_url->addAttribute('path', 'mui/index/render');

    $storageConfig = addItem($config, 'storageConfig', 'array');    
    $indexField    = addItem($storageConfig, 'indexField', 'string', $databaseIdName);
//     <item name="storageConfig" xsi:type="array">
//         <item name="indexField" xsi:type="string">pulsestorm_commercebug_log_id</item>
//     </item>                    
    
}

function generateDatasourceNode($xml, $dataSourceName, $providerClass, $databaseIdName, $requestIdName)
{
    $dataSource      = simpleXmlAddNodesXpath($xml, "dataSource[@name=$dataSourceName]");
    
    $dataProvider    = addArgument($dataSource, 'dataProvider','configurableObject');
    addArgumentsToDataProvider($dataProvider, $providerClass, $dataSourceName, 
                                $databaseIdName, $requestIdName);
    
    $data            = addArgument($dataSource, 'data','array');
    $js_config       = addItem($data, 'js_config', 'array');
    $component       = addItem($js_config, 'component', 'string', 'Magento_Ui/js/grid/provider');
    return $dataSource;
}

function addBaseColumnItemNodes($config, $width, $indexField, $sortOrder=10)
{
    addItem($config, 'resizeEnabled', 'boolean', 'false');
    addItem($config, 'resizeDefaultWidth', 'string', $width);
    addItem($config, 'indexField', 'string', $indexField);
    addItem($config, 'sortOrder', 'number', $sortOrder);
}

function addIdColumnToColumns($columns, $data, $idColumn)
{
    $columnId = $columns->addChild('column');
    $columnId->addAttribute('name', $idColumn);
    $data = addArgument($columnId, 'data', 'array');
    $config = addItem($data, 'config', 'array');
    
    addItem($config, 'filter',  'string', 'textRange');
    addItem($config, 'sorting', 'string', 'asc');
    
    $id = addItem($config, 'label',   'string', 'ID');
    $id->addAttribute('translate', 'true');

}

function addActionsColumnToColumns($columns, $pageActionsClassName, $idColumn)
{
    $actionsColumn = $columns->addChild('actionsColumn');
    $actionsColumn->addAttribute('name','actions');
    $actionsColumn->addAttribute('class',$pageActionsClassName);
    $data = addArgument($actionsColumn, 'data','array');
    $config = addItem($data, 'config', 'array');
    addBaseColumnItemNodes($config, '107', $idColumn, 200);        
    return $actionsColumn;
}

function generateColumnsNode($xml, $columnsName, $pulsestorm_commercebug_log_id, $pageActionsClassName)
{
    $columns         = simpleXmlAddNodesXpath($xml, "columns[@name=$columnsName]");    
    $sectionColumns  = $columns->addChild('selectionsColumn');
    $sectionColumns->addAttribute('name','ids');
    $data = addArgument($sectionColumns, 'data', 'array');
    $config = addItem($data, 'config', 'array');
        
    addBaseColumnItemNodes($config, '55', $pulsestorm_commercebug_log_id, 10);            
    addIdColumnToColumns($columns, $data, $pulsestorm_commercebug_log_id);
    addActionsColumnToColumns($columns, $pageActionsClassName, $pulsestorm_commercebug_log_id);
                
    return $columns;
}

function generateListingToolbar($xml)
{
    $listingToolbar = $xml->addChild('listingToolbar');
    $listingToolbar->addAttribute('name', 'listing_top');

    $settings = $xml->addChild('settings');
    $settings->addChild('sticky', 'true');

    $paging = $listingToolbar->addChild('paging');
    $paging->addAttribute('name', 'listing_paging');

    $filters = $listingToolbar->addChild('filters');
    $filters->addAttribute('name', 'listing_filters');
}

function generateDataSourceNameFromGridId($grid_id)
{
    $dataSourceName   = $grid_id . '_data_source';
    return $dataSourceName;
}

function generateColumnsNameFromGridId($grid_id)
{
    $columnsName      = $grid_id . '_columns';
    return $columnsName;
}

function generateProdiverClassFromGridIdAndModuleInfo($grid_id, $module_info)
{
    $providerClass = $module_info->vendor . '\\' . $module_info->short_name . '\\' .<commit_msg>Fix settings error in ui component<commit_after><?php
namespace Pulsestorm\Magento2\Cli\Magento2_Generate_Ui_Grid;
use function Pulsestorm\Pestle\Importer\pestle_import;
pestle_import('Pulsestorm\Pestle\Library\output');
pestle_import('Pulsestorm\Pestle\Library\exitWithErrorMessage');
pestle_import('Pulsestorm\Xml_Library\simpleXmlAddNodesXpath');    
pestle_import('Pulsestorm\Xml_Library\formatXmlString');
pestle_import('Pulsestorm\Xml_Library\getXmlNamespaceFromPrefix');
pestle_import('Pulsestorm\Magento2\Cli\Xml_Template\getBlankXml');
pestle_import('Pulsestorm\Magento2\Cli\Library\getModuleInformation');
pestle_import('Pulsestorm\Pestle\Library\writeStringToFile');
pestle_import('Pulsestorm\Magento2\Cli\Library\createClassFile');
pestle_import('Pulsestorm\Cli\Code_Generation\createClassTemplateWithUse');
pestle_import('Pulsestorm\Magento2\Cli\Library\addArgument');
pestle_import('Pulsestorm\Magento2\Cli\Library\addItem');
function generateArgumentNode($xml, $gridId, $dataSourceName, $columnsName, $collection)
{
    $shortName = getShortModelNameFromResourceModelCollection(
        $collection);    
    $fullIdentifier = $gridId . '.' . $dataSourceName;
    
    $argument   = addArgument($xml, 'data', 'array');
    $js_config  = addItem($argument,'js_config','array');
    $provider   = addItem($js_config, 'provider', 'string', $fullIdentifier);      
    $deps       = addItem($js_config, 'deps', 'string', $fullIdentifier);      
    $spinner    = addItem($argument, 'spinner', 'string', $columnsName);         
    
    $buttons    = addItem($argument, 'buttons', 'array');
    $add        = addItem($buttons, 'add', 'array');
    addItem($add, 'name', 'string', 'add');
    addItem($add, 'label', 'string', 'Add New');
    addItem($add, 'class', 'string', 'primary');
    addItem($add, 'url', 'string', '*/'.$shortName.'/new');

    return $argument;
}

function addArgumentsToDataProvider($dataProvider, $providerClass, 
            $dataSourceName, $databaseIdName, $requestIdName)
{
    addArgument($dataProvider, 'class','string',$providerClass);
    addArgument($dataProvider, 'name','string',$dataSourceName);
    addArgument($dataProvider, 'primaryFieldName','string',$databaseIdName);
    addArgument($dataProvider, 'requestFieldName','string',$requestIdName);
    $dataForProvider = addArgument($dataProvider, 'data','array');
    
    $config     = addItem($dataForProvider, 'config','array');
    $update_url = addItem($config,'update_url','url');
    $update_url->addAttribute('path', 'mui/index/render');

    $storageConfig = addItem($config, 'storageConfig', 'array');    
    $indexField    = addItem($storageConfig, 'indexField', 'string', $databaseIdName);
//     <item name="storageConfig" xsi:type="array">
//         <item name="indexField" xsi:type="string">pulsestorm_commercebug_log_id</item>
//     </item>                    
    
}

function generateDatasourceNode($xml, $dataSourceName, $providerClass, $databaseIdName, $requestIdName)
{
    $dataSource      = simpleXmlAddNodesXpath($xml, "dataSource[@name=$dataSourceName]");
    
    $dataProvider    = addArgument($dataSource, 'dataProvider','configurableObject');
    addArgumentsToDataProvider($dataProvider, $providerClass, $dataSourceName, 
                                $databaseIdName, $requestIdName);
    
    $data            = addArgument($dataSource, 'data','array');
    $js_config       = addItem($data, 'js_config', 'array');
    $component       = addItem($js_config, 'component', 'string', 'Magento_Ui/js/grid/provider');
    return $dataSource;
}

function addBaseColumnItemNodes($config, $width, $indexField, $sortOrder=10)
{
    addItem($config, 'resizeEnabled', 'boolean', 'false');
    addItem($config, 'resizeDefaultWidth', 'string', $width);
    addItem($config, 'indexField', 'string', $indexField);
    addItem($config, 'sortOrder', 'number', $sortOrder);
}

function addIdColumnToColumns($columns, $data, $idColumn)
{
    $columnId = $columns->addChild('column');
    $columnId->addAttribute('name', $idColumn);
    $data = addArgument($columnId, 'data', 'array');
    $config = addItem($data, 'config', 'array');
    
    addItem($config, 'filter',  'string', 'textRange');
    addItem($config, 'sorting', 'string', 'asc');
    
    $id = addItem($config, 'label',   'string', 'ID');
    $id->addAttribute('translate', 'true');

}

function addActionsColumnToColumns($columns, $pageActionsClassName, $idColumn)
{
    $actionsColumn = $columns->addChild('actionsColumn');
    $actionsColumn->addAttribute('name','actions');
    $actionsColumn->addAttribute('class',$pageActionsClassName);
    $data = addArgument($actionsColumn, 'data','array');
    $config = addItem($data, 'config', 'array');
    addBaseColumnItemNodes($config, '107', $idColumn, 200);        
    return $actionsColumn;
}

function generateColumnsNode($xml, $columnsName, $pulsestorm_commercebug_log_id, $pageActionsClassName)
{
    $columns         = simpleXmlAddNodesXpath($xml, "columns[@name=$columnsName]");    
    $sectionColumns  = $columns->addChild('selectionsColumn');
    $sectionColumns->addAttribute('name','ids');
    $data = addArgument($sectionColumns, 'data', 'array');
    $config = addItem($data, 'config', 'array');
        
    addBaseColumnItemNodes($config, '55', $pulsestorm_commercebug_log_id, 10);            
    addIdColumnToColumns($columns, $data, $pulsestorm_commercebug_log_id);
    addActionsColumnToColumns($columns, $pageActionsClassName, $pulsestorm_commercebug_log_id);
                
    return $columns;
}

function generateListingToolbar($xml)
{
    $listingToolbar = $xml->addChild('listingToolbar');
    $listingToolbar->addAttribute('name', 'listing_top');

    $settings = $listingToolbar->addChild('settings');
    $settings->addChild('sticky', 'true');

    $paging = $listingToolbar->addChild('paging');
    $paging->addAttribute('name', 'listing_paging');

    $filters = $listingToolbar->addChild('filters');
    $filters->addAttribute('name', 'listing_filters');
}

function generateDataSourceNameFromGridId($grid_id)
{
    $dataSourceName   = $grid_id . '_data_source';
    return $dataSourceName;
}

function generateColumnsNameFromGridId($grid_id)
{
    $columnsName      = $grid_id . '_columns';
    return $columnsName;
}

function generateProdiverClassFromGridIdAndModuleInfo($grid_id, $module_info)
{
    $providerClass = $module_info->vendor . '\\' . $module_info->short_name . '\\' .
{'fraction_non_alphanumeric': 0.16094453938169956, 'fraction_numerical': 0.0029516855678110923, 'mean_word_length': 5.096117424242424, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 17}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1116510', 'n_tokens_mistral': 4032, 'n_tokens_neox': 4001, 'n_words': 587}