<?php

/**
 * 本文件属于 DBErp 进销存系统。
 *
 * 版权所有 © 2026 北京珑大钜商科技有限公司。保留所有权利。
 *
 * 未经官方授权，不得删除、篡改或隐藏本文件中的版权声明、产品标识与来源信息。
 * 商业授权、官方更新与技术支持服务，请以珑大官方支持中心记录为准。
 *
 * @link https://support.loongdom.cn
 * @see  https://www.dberp.com.cn
 */

use App\Http\Controllers\DataImport\DataImportFailedRowsExportController;
use App\Http\Controllers\DocumentPrintController;
use App\Http\Controllers\InventoryWarningExportController;
use App\Http\Controllers\Report\ReportExportController;
use App\Http\Controllers\Settlement\SettlementStatementExportController;
use App\Services\Install\DBErpInstallStatus;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Route;

$documentRoutes = Route::middleware(['auth', 'dberp.installed']);
$panelPath = trim((string) config('dberp.admin.panel_path', ''), '/');
if ($panelPath !== '') {
    $documentRoutes = $documentRoutes->prefix($panelPath);
}

$documentRoutes->group(function (): void {
    Route::get('/inventory-warnings/export', InventoryWarningExportController::class)
        ->name('dberp.inventory-warnings.export');

    Route::get('/reports/export/{report}', ReportExportController::class)
        ->name('dberp.reports.export');

    Route::get('/settlement-statements/{statement}/export', SettlementStatementExportController::class)
        ->name('dberp.settlement-statements.export');

    Route::get('/documents/{documentKey}/{record}/print', DocumentPrintController::class)
        ->name('dberp.documents.print');

    Route::get('/data-import-batches/{batch}/failed-rows/export', DataImportFailedRowsExportController::class)
        ->name('dberp.data-import-batches.failed-rows.export');
});

if ($panelPath === '') {
    Route::get('admin', function (): RedirectResponse {
        if (! app(DBErpInstallStatus::class)->isInstalled()) {
            return redirect()->route('install.welcome');
        }

        return redirect()->route('filament.admin.auth.login');
    });
}
