<?php

namespace Modules\LandedCost\Http\Controllers;

use Illuminate\Routing\Controller;

/**
 * Hook controller discovered by the core app's ModuleUtil::getModuleData().
 *
 * `get_additional_script` is collected by the layouts.* view composer
 * (App\Providers\AppServiceProvider) and rendered into every admin page. We use it to
 * inject the landed-cost modal + a small script that adds the "Landed Cost" item into
 * each core Purchases / Purchase Orders row action menu — so the feature works from a
 * module-only upload, with no edits to the core application files.
 */
class DataController extends Controller
{
    public function get_additional_script()
    {
        // Only for users allowed to manage landed cost.
        if (!auth()->check() || !auth()->user()->can('landed_cost.manage')) {
            return [];
        }

        // Only on the core Purchases / Purchase Orders screens (where the action menu lives).
        if (!request()->is('purchases', 'purchases/*', 'purchase-order', 'purchase-order/*')) {
            return [];
        }

        return [
            'additional_views' => [
                'landedcost::modal',   // the expenses / apply modal + its JS
                'landedcost::inject',  // adds the action-menu item per row
            ],
        ];
    }
}
