@extends('admin.layouts.app')

@section('content')
<div class="container-fluid">
    <h2>복구 / 최적화</h2>
    <hr/>
    @include('admin.messages')

    <div class="row mb-3">
        <label for="btnClearCache" class="col-sm-3 col-form-label">
            Clear Application Cache
            <div class="form-text text-muted">php artisan cache:clear</div>
        </label>
        <div class="col-sm-9 align-self-center">
            <button type="button" id="btnClearCache" class="btn btn-warning btn-cache-clear" value="appCache">삭제</button>
        </div>
    </div>
    <hr/>
    <div class="row mb-3">
        <label for="btnRouteCache" class="col-sm-3 col-form-label">
            Clear Route Cache
            <div class="form-text text-muted">php artisan route:clear</div>
        </label>
        <div class="col-sm-9 align-self-center">
            <button type="button" id="btnRouteCache" class="btn btn-warning btn-cache-clear" value="routeCache">삭제</button>
        </div>
    </div>
    <hr/>
    <div class="row mb-3">
        <label for="btnConfigCache" class="col-sm-3 col-form-label">
            Clear Configuration Cache
            <div class="form-text text-muted">php artisan config:clear</div>
        </label>
        <div class="col-sm-9 align-self-center">
            <button type="button" id="btnConfigCache" class="btn btn-warning btn-cache-clear" value="configCache">삭제</button>
        </div>
    </div>
    <hr/>
    <div class="row mb-3">
        <label for="btnViewCache" class="col-sm-3 col-form-label">
            Clear Compiled Views Cache
            <div class="form-text text-muted">php artisan view:clear</div>
        </label>
        <div class="col-sm-9 align-self-center">
            <button type="button" id="btnViewCache" class="btn btn-warning btn-cache-clear" value="viewCache">삭제</button>
        </div>
    </div>
    <hr/>
</div>

<script type="module">
$(document).on("click", ".btn-cache-clear", function() {
    let cmd = this.value;
    let msg = "";
    switch (cmd) {
        case "appCache" :
            msg = "Application Cache";
            break;
        case "routeCache" :
            msg = "Route Cache";
            break;
        case "configCache" :
            msg = "Configuration Cache";
            break;
        case "viewCache" :
            msg = "Compiled Views Cache";
            break;
    }
    msg += "를 삭제하시겠습니까?";

    if (confirm(msg)) {
        location.href = ADMIN_URL + "/config/optimize/clear/" + cmd;
    }
});
</script>
@endsection
