<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Admin\AuthController;
use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\CustomerController;
use App\Http\Controllers\Admin\TailorController;
use App\Http\Controllers\Admin\BookingController;
use App\Http\Controllers\Admin\SpecializationController;
use App\Http\Controllers\Admin\WithdrawalController;
use App\Http\Controllers\Admin\BankAccountController;

// Add js config route at the beginning
Route::get('js/config.js', function () {
    return response()
        ->view('admin.js.config')
        ->header('Content-Type', 'application/javascript');
})->name('js.config');

Route::get('/', function () {
    return redirect()->route('admin.login');
});

// Admin Authentication Routes
Route::get('/admin/login', [AuthController::class, 'showLoginForm'])->name('admin.login');
Route::post('/admin/login', [AuthController::class, 'login'])->name('admin.login.submit');
Route::post('/admin/logout', [AuthController::class, 'logout'])->name('admin.logout');

// Admin Routes
Route::middleware(['auth', 'admin'])->prefix('admin')->name('admin.')->group(function () {
    Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');
    Route::get('/profile', function () {
        return view('admin.user.admin');
    })->name('user.profile');
    Route::resource('customers', CustomerController::class);
    Route::resource('tailors', TailorController::class);
    Route::get('/bookings', [BookingController::class, 'index'])->name('bookings.index');
    Route::resource('specializations', SpecializationController::class);
    
    // Penarikan Dana Routes
    Route::controller(WithdrawalController::class)->group(function () {
        Route::get('/withdrawals/pending', 'pending')->name('withdrawals.pending');
        Route::get('/withdrawals/history', 'history')->name('withdrawals.history');
        Route::get('/withdrawals/{withdrawal}/process', 'showProcess')->name('withdrawals.show-process');
        Route::post('/withdrawals/{withdrawal}/process', 'process')->name('withdrawals.process');
    });
    
    // Akun Bank Routes
    Route::controller(BankAccountController::class)->group(function () {
        Route::get('/bank-accounts/pending', 'pending')->name('bank-accounts.pending');
        Route::get('/bank-accounts/verified', 'verified')->name('bank-accounts.verified');
        Route::get('/bank-accounts/{bankAccount}', 'detail')->name('bank-accounts.detail');
        Route::get('/bank-accounts/{bankAccount}/verify', 'showVerify')->name('bank-accounts.show-verify');
        Route::post('/bank-accounts/{bankAccount}/verify', 'verify')->name('bank-accounts.verify');
    });
});
