<?php

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

$aColumns = [
    'ig.name as item_group',
    'a.name',
];

$sIndexColumn = 'a.id';
$sTable       = db_prefix() . 'acabamentos a';

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

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

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

    $row[] = $aRow['item_group'] ?? "--";
    $row[] = $aRow['name'];

    $options = '<div class="tw-flex tw-items-center tw-space-x-2">';
    $options .= '<a href="' . admin_url('acabamentos/acabamento/' . $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('acabamentos/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;
}