<?php

namespace App\DataTables;

use App\Models\Zone;
use Yajra\DataTables\Facades\DataTables;

class ZoneDataTable
{
    public function render($request)
    {
        $query = Zone::with('parent');

        return DataTables::of($query)
            ->addColumn('parent_name', function (Zone $zone) {
                return $zone->parent?->name ?? '-';
            })
            ->addColumn('type_label', function (Zone $zone) {
                return $zone->parent_id
                    ? '<span class="badge bg-secondary">Subzone</span>'
                    : '<span class="badge bg-primary">Zone</span>';
            })
            ->addColumn('status_label', function (Zone $zone) {
                return $zone->status
                    ? '<span class="badge bg-success">Active</span>'
                    : '<span class="badge bg-secondary">Inactive</span>';
            })
            ->addColumn('actions', function (Zone $zone) {
                return view('admin.zones.partials.actions', compact('zone'))->render();
            })
            ->rawColumns(['type_label', 'status_label', 'actions'])
            ->make(true);
    }
}
