<?php echo $this->profileheader($this->customer);?>

<div class="resp-tabs-container tab_identifier_parent no-padding">
    <div>
        <div class="client-contact-wrapper" id="profile-fields">
            <div class="cm-holder settings-wrapper dt-info">
                <div class="head d-flex align-items-center flex-wrap gap-3">
                </div>
                <div class="dt-wrapper pull-top">
                    <div class="table-responsive">
                        <table id="table-list" class="display" style="width:100%">
                            <thead>
                                <tr>
                                    <th></th>
                                    <th class=""><?php echo $this->user->lang('Subject'); ?></th>
                                    <th class=""><?php echo $this->user->lang('Date'); ?></th>
                                    <th class=""><?php echo $this->user->lang('To'); ?></th>
                                    <th class=""><?php echo $this->user->lang('From'); ?></th>
                                </tr>
                            </thead>
                        </table>
                    </div>
                    <div class="table-actions">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>

 $(document).ready(function() {
    var ajaxUrl = 'index.php?fuse=clients&action=getemaillist&controller=email';
    profilenotes.table = $('#table-list').DataTable({
        "searching": false,
        "ajax": {
            url: ajaxUrl,
            dataSrc: 'data',
            data: function(d) {
                d.customerId = clientexec.customerId;
                d.limit = -1;
            }
        },
        "columns": [
            {
                "className": 'details-control',
                "orderable": false,
                "data": null,
                "defaultContent": ''
            },
            {
                "data": "subject",
            },
            {
                "data": "date",
            },
            {
                "data": "to",
            },
            {
                "data": "from",
                render: function(data, type, record) {
                    if (record.fromName == '') {
                        return 'N/A';
                    }
                    return record.fromName + ' (' + record.sender + ')';
                }
            },
        ],
        "order": [[2, 'asc']]
    });

    $('#table-list tbody').on('click', 'td.details-control', function () {
        var tr = $(this).closest('tr');
        var row = profilenotes.table.row(tr);
        var data = row.data();

        if (row.child.isShown()) {
            row.child.hide();
            tr.removeClass('shown');
        }
        else {
            var expanderBody = data.content;
            row.child(expanderBody).show();
            tr.addClass('shown');
        }
    });
});
</script>