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


class Ads extends CI_Controller
{

    public function __construct()
    {
        parent::__construct();
    }

    public function view_list()
    {
        $datas = $this->ads->get_data_table(['remove' => '0']);
        // print_r($this->db->last_query());
        // exit;

        $final = [];
        $sno = $_POST['start'];
        foreach ($datas as $data) {
            $row = [];
            $image = $data['thumbnail'];
            $row[] = ++$sno;
            $row[] = $data['title'];
            if($data['occurance'] == '1'){
                $row[] = "<span class='rounded p-2 bg-success text-light'>Low</span>";
            }
            if($data['occurance'] == '2'){
                $row[] = "<span class='rounded p-2 bg-warning text-light'>Medium</span>";
            }
            if($data['occurance'] == '3'){
                $row[] = "<span class='rounded p-2 bg-danger text-light'>High</span>";
            }
            $row[] = "<img src='$image' class='img-fluid w-25' alt='thumbnail' >";
            $row[] = $data['target'];
            $row[] = $data['watched'];
        //     $row[] = "<div class='btn-group' role='group' aria-label='Basic example'>
        //     <a type='button' href='' class='btn btn-primary'><i class='fa-solid fa-eye'></i></a>
        //     <button type='button' class='btn btn-primary'><i class='fa-solid fa-trash'></i></button>
        // </div>";

        $row[] = "
        <div class='btn-group' role='group'>
            <a href='" . site_url('/admin/ads/view/' . $data['id']) . "' class='btn btn-info' title='View'><i class='fa fa-eye'></i></a>
            <a href='" . site_url('/admin/ads/edit?id=' . $data['id']) . "' class='btn btn-primary' title='Edit'><i class='fa fa-edit'></i></a>
            <a href='" . site_url('/admin/ads/delete?id=' . $data['id']) . "' class='btn btn-danger' title='Delete' onclick='return confirm(\"Are you sure?\")'><i class='fa fa-trash'></i></a>
        </div>";
    


            $final[] = $row;
        }

        $output = array(
            "draw" => $_POST['draw'],
            "recordsTotal" => $this->ads->count_all_data(['remove' => '0']),
            "recordsFiltered" => $this->ads->count_filtered_data(['remove' => '0']),
            "data" => $final,
        );

        $this->output->set_content_type('application/json')->set_output(json_encode($output));

        // print_r($data);exit;

        // echo json_encode($final);
    }

}
