
<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Auth;
use App\Models\User;
use App\Http\Controllers\Controller;
use App\Http\Controllers\InquiryConfirmController;
use App\Http\Controllers\LoginController;
use App\Http\Controllers\MemberRegistrationController;
use App\Http\Controllers\PasswordReminderController;
use App\Http\Controllers\UserInfoController;
use App\Http\Controllers\UserEditController;
use App\Http\Controllers\UserEditConfirmController;
use App\Http\Controllers\UserWithdrawController;
use App\Http\Controllers\RegularContractController;
use App\Http\Controllers\RegularContractCreateController;
use App\Http\Controllers\ParkingSearchController;
use App\Http\Controllers\ParkWaitlistController;
use App\Http\Controllers\ReceiptController;
use App\Http\Controllers\ParkDetailController;

// 画面遷移のみ
Route::get('/', function () { return view('general.swo1_1'); })->name('swo1_1');
Route::get('/swo2_1', function () { return view('general.swo2_1'); })->name('swo2_1');
Route::get('/swo3_1', function () { return view('general.swo3_1'); })->name('swo3_1');
Route::get('/swo3_2', function () { return view('general.swo3_2'); })->name('swo3_2');
Route::get('/swo3_3', function () { return view('general.swo3_3'); })->name('swo3_3');
Route::get('/swo6_1', function () { return view('general.swo6_1'); })->name('swo6_1');
Route::get('/swo8_1', function () { return view('general.swo8_1'); })->name('swo8_1');
Route::get('/swo8_2', function () { return view('general.swo8_2'); })->name('swo8_2');
Route::get('/swo9_1', function () { return view('general.swo9_1'); })->name('swo9_1');
Route::get('/swo9_2', function () { return view('general.swo9_2'); })->name('swo9_2');
Route::get('/swo9_3', function () { return view('general.swo9_3'); })->name('swo9_3');
Route::get('/swo9_4', function () { return view('general.swo9_4'); })->name('swo9_4');
Route::get('/swo9_5', function () { return view('general.swo9_5'); })->name('swo9_5');
Route::get('/swo10_1', function () { return view('general.swo10_1'); })->name('swo10_1');
Route::get('/swo11_1', function () { return view('general.swo11_1'); })->name('swo11_1');
Route::get('/swo12_1', function () { return view('general.swo12_1'); })->name('swo12_1');
Route::get('/swo13_1', function () { return view('general.swo13_1'); })->name('swo13_1');
Route::get('/swo14_1', function () { return view('general.swo14_1'); })->name('swo14_1');
Route::get('/swo15_1', function () { return view('general.swo15_1'); })->name('swo15_1');
Route::get('/swo15_2', function () { return view('general.swo15_2'); })->name('swo15_2');
Route::get('/swo16_1', function () { return view('general.swo16_1'); })->name('swo16_1');
Route::get('/swo17_1', function () { return view('general.swo17_1'); })->name('swo17_1');
Route::get('/error', function () { return view('general.error'); })->name('error');

// コントローラー経由
Route::post('/swo2_2', [MemberRegistrationController::class, 'sendMail'])->name('swo2_2');
Route::get('/swo2_3', [MemberRegistrationController::class, 'index'])->name('swo2_3')->middleware('signed');
Route::post('/swo2_4', [MemberRegistrationController::class, 'confirm'])->name('swo2_4');
Route::post('/swo2_5',  [MemberRegistrationController::class, 'complete'])->name('swo2_5');
Route::get('/swo4_1', [LoginController::class, 'login'])->name('swo4_1');
Route::get('/swo5_1', [ParkingSearchController::class, 'index'])->name('swo5_1');
Route::get('/swo7_1', [InquiryConfirmController::class, 'index'])->name('swo7_1');
Route::post('/swo7_2',[InquiryConfirmController::class, 'confirm'])->name('swo7_2');
Route::post('/swo7_3',[InquiryConfirmController::class, 'complete'])->name('swo7_3');
Route::post('/swo8_3', [PasswordReminderController::class, 'sendMail'])->name('swo8_3');

// ログイン画面へのリダイレクト
Route::get('/login', function () {
    return redirect()->route('swo8_1');
})->name('login');

// マイページ画面へのリダイレクト
Route::get('/mypage', function () {
    return 'マイページ（仮）';
})->name('mypage');

// ユーザー情報確認画面
Route::get('/user/info', [UserInfoController::class, 'show'])
    ->name('user.info');

// ユーザー情報編集画面（GET: 編集フォーム表示）
Route::get('/user/edit', [UserEditController::class, 'show'])
    ->name('user.edit');

// ユーザー情報編集（POST: 編集内容保存）
Route::post('/user/edit', [UserEditController::class, 'update'])
    ->name('user.edit.post');

// ユーザー情報編集確認
Route::get('/user/edit/confirm', [UserEditConfirmController::class, 'show'])
    ->name('user.confirm');

// 入力内容確認画面から「変更を確定する」ボタン押下時（認証メール送信）
Route::post('/user/edit/submit', [UserEditConfirmController::class, 'submit'])
    ->name('user.edit.submit');

// 認証メール内URLクリック時（変更確定処理）
Route::get('/user/edit/verify', [UserEditConfirmController::class, 'verify'])
    ->name('user.edit.verify');

// 退会画面（GET: 退会確認）
Route::get('/user/withdraw', [UserWithdrawController::class, 'showConfirm'])
    ->name('user.withdraw');
// 退会処理（POST: 退会確定）
Route::post('/user/withdraw/confirm', [UserWithdrawController::class, 'withdraw'])
    ->name('user.withdraw.confirm');

// 定期契約情報確認
Route::get('regular_contract/info', [RegularContractController::class, 'showInfo'])
    ->name('regular_contract.info');

// 領収書宛名入力画面
Route::get('receipt/input/{contract_id}', [ReceiptController::class, 'input'])
    ->name('receipt.input');
Route::get('receipt/download/{contract_id}', [ReceiptController::class, 'download'])
    ->name('receipt.download');
Route::post('receipt/issue/{contract_id}', [ReceiptController::class, 'issue']);

// 新規定期契約画面
Route::get('regular_contract/create', [RegularContractCreateController::class, 'show'])
    ->name('regular_contract.create');
Route::get('/api/park-detail/{park_id}', [ParkDetailController::class, 'show']);
Route::get('/regular-contract/regulationCheck', [RegularContractCreateController::class, 'regulationCheck']);
Route::get('/regular-contract/regulation', [RegularContractCreateController::class, 'showRegulation'])
    ->name('regular_contract.regulation');
Route::post('/regular-contract/insertRegulation', [RegularContractCreateController::class, 'insertRegulation']);
Route::get('/regular-contract/input', [RegularContractCreateController::class, 'showContractForm'])->name('regular_contract.input');
Route::post('/regular_contract/input/check', [RegularContractCreateController::class, 'inputCheck'])->name('regular_contract.input.check');
Route::get('/regular-contract/upload_identity_create', [RegularContractCreateController::class, 'showUploadIdentityCreate'])->name('regular_contract.upload_identity_create');

Route::post('regular_contract/confirm_upload_identity/{contract_id}', [RegularContractCreateController::class, 'confirmUploadIdentity'])->name('regular_contract.confirm_upload_identity');
Route::get('regular_contract/create_confirm', [RegularContractCreateController::class, 'createConfirm'])->name('regular_contract.create_confirm');
Route::post('/regular_contract/create_confirm_next/{contract_id}', [RegularContractCreateController::class, 'createConfirmNext'])->name('regular_contract.create_confirm_next');
Route::post('regular_contract/create_select_period', [RegularContractCreateController::class, 'selectPeriod'])
    ->name('regular_contract.create_select_period');
// 定期契約更新
Route::get('regular_contract/update', [RegularContractController::class, 'showInfo'])
    ->name('regular_contract.update');
Route::get('regular_contract/update/{contract_id}', [RegularContractController::class, 'update']);
// 契約区分確認
Route::get('regular_contract/confirm_category/{contract_id}', [RegularContractController::class, 'confirmCategory'])
    ->name('regular_contract.confirm_category');
Route::get('regular_contract/confirm_category_next/{contract_id}', [RegularContractController::class, 'confirmCategoryNext'])
    ->name('regular_contract.confirm_category_next');
// 本人確認書類アップロード
Route::get('regular_contract/upload_identity/{contract_id}', [RegularContractController::class, 'uploadIdentity'])
    ->name('regular_contract.upload_identity');
// 本人確認書類確認中
Route::post('regular_contract/upload_identity/{contract_id}', [RegularContractController::class, 'uploadIdentitySubmit'])
    ->name('regular_contract.upload_identity_submit');
// 利用期間選択
Route::get('regular_contract/select_period/{contract_id}', [RegularContractController::class, 'selectPeriod'])
    ->name('regular_contract.select_period');
Route::post('regular_contract/update_period', [RegularContractController::class, 'updatePeriod'])
    ->name('regular_contract.update_period');

// 定期契約履歴
Route::get('regular_contract/history', [RegularContractController::class, 'showHistory'])
    ->name('regular_contract.history');

// 空き待ち状況確認画面
Route::get('park_waitlist', [ParkWaitlistController::class, 'index'])
    ->name('park_waitlist.index');

Route::post('/login', function (Request $request) {
    $user_id = $request->input('user_id');
    Session::put('user_id', $user_id); // 入力されたIDをそのまま保存
    return redirect('/user/info'); // 認証なしでリダイレクト
});

// ウェルネット決済画面（仮）
Route::get('/wellnet/payment', function (): mixed {
    $html = <<<HTML
    <!DOCTYPE html>
    <html lang="ja">
    <head>
        <meta charset="UTF-8">
        <title>ウェルネット決済画面（仮）</title>
        <style>
            body { background:#f7f7f7; font-family:sans-serif; }
            .pay-container {
                max-width:500px; margin:40px auto; background:#fff; border-radius:10px;
                box-shadow:0 2px 8px rgba(0,0,0,0.08); padding:32px 24px;
            }
            .pay-title { font-size:1.2em; font-weight:bold; margin-bottom:12px; }
            .pay-section { margin-bottom:24px; }
            .pay-row { display:flex; align-items:center; margin-bottom:8px; }
            .pay-label { width:140px; font-weight:bold; }
            .pay-icons img { height:22px; margin-right:6px; vertical-align:middle; }
            .pay-bank-icons img { height:18px; margin-right:4px; vertical-align:middle; }
            .pay-box { background:#e6f7e6; border:1px solid #7ed957; border-radius:6px; padding:8px 12px; margin-bottom:8px; }
        </style>
    </head>
    <body>
        <div class="pay-container">
            <div class="pay-section">
                <div class="pay-title">クレジットでのお支払い</div>
                <div class="pay-box">
                    <span class="pay-label">クレジット</span>
                </div>
            </div>
            <div class="pay-section">
                <div class="pay-title">コンビニでのお支払い</div>
                <div class="pay-box"><span class="pay-label">ローソン</span><span class="pay-icons"></span></div>
                <div class="pay-box"><span class="pay-label">ファミリーマート</span><span class="pay-icons"></span></div>
                <div class="pay-box"><span class="pay-label">サークルKサンクス</span><span class="pay-icons"></span></div>
                <div class="pay-box"><span class="pay-label">ミニストップ</span><span class="pay-icons"></span></div>
                <div class="pay-box"><span class="pay-label">セイコーマート</span><span class="pay-icons"></span></div>
                <div class="pay-box"><span class="pay-label">デイリーヤマザキ</span><span class="pay-icons"></span></div>
            </div>
            <div class="pay-section">
                <div class="pay-title">銀行でのお支払い</div>
                <div class="pay-box">
                    <span class="pay-label">ATM</span>
                </div>
                <div class="pay-box">
                    <span class="pay-label">ネットバンキング</span>
                </div>
            </div>
        </div>
    </body>
    </html>
    HTML;
    return $html;
})->name('wellnet.payment');
