<?php

defined('BASEPATH') or exit('No direct script access allowed');

$aColumns = [
    'm.name',
    'ig.name as item_group_name',
    'm.espessura',
    'm.altura',
    'm.comprimento',
    'm.valor'
];

$sIndexColumn = 'm.id';
$sTable       = db_prefix() . 'item_group_materials m';

$join = [
    'LEFT JOIN ' . db_prefix() . 'items_groups ig ON ig.id = m.item_group_id',
];

$result       = data_tables_init($aColumns, $sIndexColumn, $sTable, $join, [], ['m.id']);
$output       = $result['output'];
$rResult      = $result['rResult'];

foreach ($rResult as $aRow) {
    $row = [];

    $row[] = $aRow['name'];
    $row[] = $aRow['item_group_name'];
    $row[] = $aRow['espessura'];
    $row[] = $aRow['altura'];
    $row[] = $aRow['comprimento'];
    $row[] = $aRow['valor'];

    $options = '<div class="tw-flex tw-items-center tw-space-x-2">';
    $options .= '<a href="' . admin_url('item_group_materials/material/' . $aRow['id']) . '" class="tw-text-neutral-500 hover:tw-text-neutral-700">
        <i class="fa-regular fa-pen-to-square fa-lg"></i>
    </a>';
    $options .= '<a href="' . admin_url('item_group_materials/delete/' . $aRow['id']) . '" class="tw-text-neutral-500 hover:tw-text-neutral-700 _delete">
        <i class="fa-regular fa-trash-can fa-lg"></i>
    </a>';
    $options .= '</div>';

    $row[] = $options;

    $output['aaData'][] = $row;
}