<?php

use Illuminate\Support\Facades\Auth;

\View::share('printSupplierSourceVersion', config('app.version'));

$fulfillScript = function () 
{
    $currentPath = request()->path();
    $currentLocale = env('APP_LOCALE');

    if (!empty($currentLocale)) {
        $currentPath = str_replace("$currentLocale/", '', $currentPath);
    }

    if (strpos($currentPath, 'admin/orders') !== false || strpos($currentPath, 'fulfillment-board/index') !== false)
    {
        $dataConfigs = \Config::get('print-suppliers::connection');

        $configs = [];
        if(isset(Auth::user()->email)) {
            $configs['user_email'] = Auth::user()->email;
            $configs['currentLocale'] = $currentLocale;
        }

        foreach ($dataConfigs as $key => $value) {
            switch ($key) {
                case 'printify': $configs['printify'] = loadPrintifyConfigs($value); break;
                case 'gelato': $configs['gelato'] = loadGelatoConfigs($value); break;
            }
        }
        
        return view('print-suppliers::suppliers.fullfill-controller', [
            'configs' => $configs
        ]);
    }
};

Module::onView('module-script', $fulfillScript);

Module::onView('orderlist-order-action', function () {
    return view('print-suppliers::includes.button-fulfill-action');
});

Module::onView('printify-info-order-action', function () {
    return view('print-suppliers::includes.button-printify-info-action');
});

Module::onView('fulfill-action-dashboard', function () {
    return view('print-suppliers::includes.button-fulfill-action-for-dashboard');
});

Module::onView('system-orders-includes', function () {
    return view('print-suppliers::suppliers.fullfill-modal');
});

Module::onView('fulfill-angular-directive', function () {
    return 'fulfillbase fulfillprintify fulfillgelato fulfillprintlogistic fulfillmerchize fulfillproluxury fulfillteezily fulfilltoaddit fulfillbondre'; // viết thường hết để tránh lỗi
});

Module::onView('system.menu', function () {
    if(hasPermission('module/print-suppliers') ) {
        return view('print-suppliers::includes.menu');
    }
});