@extends('vendor.installer.layouts.master')

@section('template_title')
    {{ trans('installer_messages.environment.wizard.templateTitle') }}
@endsection

@section('title')
    <i class="fa fa-magic fa-fw" aria-hidden="true"></i>
    {!! trans('installer_messages.environment.wizard.title') !!}
@endsection

@section('container')
    <div class="tabs tabs-full">

        <input id="tab1" type="radio" name="tabs" class="tab-input" checked />
        <label for="tab1" class="tab-label">
            <i class="fa fa-shopping-bag fa-2x fa-fw" aria-hidden="true"></i>
            <br />
            Data Toko
        </label>

        <input id="tab2" type="radio" name="tabs" class="tab-input" />
        <label for="tab2" class="tab-label">
            <i class="fa fa-database fa-2x fa-fw" aria-hidden="true"></i>
            <br />
            Database
        </label>

        <input id="tab3" type="radio" name="tabs" class="tab-input" />
        <label for="tab3" class="tab-label">
            <i class="fa fa-check fa-2x fa-fw" aria-hidden="true"></i>
            <br />
            Selesai
        </label>

        <form method="post" action="{{ route('LaravelInstaller::environmentSaveWizard') }}" class="tabs-wrap">
            <div class="tab" id="tab1content">
                <input type="hidden" name="_token" value="{{ csrf_token() }}">

                {{-- ================================================= --}}
                {{-- SETTINGAN TERSEMBUNYI (DEFAULT) --}}
                {{-- ================================================= --}}
                
                {{-- 1. Paksa jadi Production (Biar aman) --}}
                <input type="hidden" name="environment" value="production">
                
                {{-- 2. Matikan Debug (Biar error tidak bocor ke user) --}}
                <input type="hidden" name="app_debug" value="false">
                
                {{-- 3. Log Level standar --}}
                <input type="hidden" name="app_log_level" value="error">

                {{-- 4. App Name Default --}}
                <input type="hidden" name="app_name" value="Aplikasi POS">

                {{-- 5. URL (Otomatis ambil URL saat ini) --}}
                <input type="hidden" name="app_url" value="{{ request()->root() }}">


                {{-- ================================================= --}}
                {{-- INPUT YANG MUNCUL (HANYA LISENSI & TOKO) --}}
                {{-- ================================================= --}}

                <div class="block-separator" style="border-bottom: 1px solid #eee; margin-bottom: 20px; padding-bottom: 10px;">
                    <h4 style="text-align: center;">🔐 Setup Identitas Toko</h4>
                    <p style="text-align: center; font-size: 0.9em; color: #666;">Silakan masukkan data lisensi yang Anda terima dari developer.</p>
                </div>

                {{-- 1. NAMA TOKO --}}
                <div class="form-group {{ $errors->has('APP_CLIENT_NAME') ? ' has-error ' : '' }}">
                    <label for="APP_CLIENT_NAME">Nama Toko / Klien</label>
                    <input type="text" name="APP_CLIENT_NAME" id="APP_CLIENT_NAME" value="" placeholder="Contoh: Toko Maju Jaya" />
                    @if ($errors->has('APP_CLIENT_NAME'))
                        <span class="error-block">
                            <i class="fa fa-fw fa-exclamation-triangle" aria-hidden="true"></i>
                            {{ $errors->first('APP_CLIENT_NAME') }}
                        </span>
                    @endif
                </div>

                {{-- 2. LICENSE KEY --}}
                <div class="form-group {{ $errors->has('APP_LICENSE_KEY') ? ' has-error ' : '' }}">
                    <label for="APP_LICENSE_KEY">License Key (Serial Number)</label>
                    <input type="text" name="APP_LICENSE_KEY" id="APP_LICENSE_KEY" value="" placeholder="Masukkan kunci dari developer" />
                    @if ($errors->has('APP_LICENSE_KEY'))
                        <span class="error-block">
                            <i class="fa fa-fw fa-exclamation-triangle" aria-hidden="true"></i>
                            {{ $errors->first('APP_LICENSE_KEY') }}
                        </span>
                    @endif
                </div>

                {{-- 3. PPN RATE --}}
                <div class="form-group {{ $errors->has('PPN_RATE') ? ' has-error ' : '' }}">
                    <label for="PPN_RATE">Tarif PPN (Desimal)</label>
                    <input type="text" name="PPN_RATE" id="PPN_RATE" value="0.11" placeholder="Contoh: 0.11 (untuk 11%)" />
                    @if ($errors->has('PPN_RATE'))
                        <span class="error-block">
                            <i class="fa fa-fw fa-exclamation-triangle" aria-hidden="true"></i>
                            {{ $errors->first('PPN_RATE') }}
                        </span>
                    @endif
                </div>

                <div class="block-separator" style="border-top: 1px dashed #ccc; margin: 20px 0; padding-top: 20px;">
                    <h4 style="text-align: center; margin-bottom: 20px;">🤖 Notifikasi Telegram (Opsional)</h4>
                </div>

                {{-- 4. TELEGRAM TOKEN --}}
                <div class="form-group {{ $errors->has('TELEGRAM_BOT_TOKEN') ? ' has-error ' : '' }}">
                    <label for="TELEGRAM_BOT_TOKEN">Telegram Bot Token</label>
                    <input type="text" name="TELEGRAM_BOT_TOKEN" id="TELEGRAM_BOT_TOKEN" value="" placeholder="Token dari BotFather (Boleh dikosongkan)" />
                </div>

                {{-- 5. TELEGRAM CHAT ID --}}
                <div class="form-group {{ $errors->has('TELEGRAM_CHAT_ID') ? ' has-error ' : '' }}">
                    <label for="TELEGRAM_CHAT_ID">Telegram Chat ID</label>
                    <input type="text" name="TELEGRAM_CHAT_ID" id="TELEGRAM_CHAT_ID" value="" placeholder="ID Chat Penerima (Boleh dikosongkan)" />
                </div>

                <div class="buttons">
                    <button class="button" onclick="showDatabaseSettings();return false">
                        Lanjut Setup Database
                        <i class="fa fa-angle-right fa-fw" aria-hidden="true"></i>
                    </button>
                </div>
            </div>

            <div class="tab" id="tab2content">

                <div class="block-separator" style="border-bottom: 1px solid #eee; margin-bottom: 20px; padding-bottom: 10px;">
                    <h4 style="text-align: center;">🗄️ Koneksi Database</h4>
                </div>

                <div class="form-group {{ $errors->has('database_connection') ? ' has-error ' : '' }}">
                    <label for="database_connection">
                        {{ trans('installer_messages.environment.wizard.form.db_connection_label') }}
                    </label>
                    <select name="database_connection" id="database_connection">
                        <option value="mysql" selected>{{ trans('installer_messages.environment.wizard.form.db_connection_label_mysql') }}</option>
                        <option value="sqlite">{{ trans('installer_messages.environment.wizard.form.db_connection_label_sqlite') }}</option>
                        <option value="pgsql">{{ trans('installer_messages.environment.wizard.form.db_connection_label_pgsql') }}</option>
                        <option value="sqlsrv">{{ trans('installer_messages.environment.wizard.form.db_connection_label_sqlsrv') }}</option>
                    </select>
                    @if ($errors->has('database_connection'))
                        <span class="error-block">
                            <i class="fa fa-fw fa-exclamation-triangle" aria-hidden="true"></i>
                            {{ $errors->first('database_connection') }}
                        </span>
                    @endif
                </div>

                <div class="form-group {{ $errors->has('database_hostname') ? ' has-error ' : '' }}">
                    <label for="database_hostname">
                        {{ trans('installer_messages.environment.wizard.form.db_host_label') }}
                    </label>
                    <input type="text" name="database_hostname" id="database_hostname" value="127.0.0.1" placeholder="{{ trans('installer_messages.environment.wizard.form.db_host_placeholder') }}" />
                    @if ($errors->has('database_hostname'))
                        <span class="error-block">
                            <i class="fa fa-fw fa-exclamation-triangle" aria-hidden="true"></i>
                            {{ $errors->first('database_hostname') }}
                        </span>
                    @endif
                </div>

                <div class="form-group {{ $errors->has('database_port') ? ' has-error ' : '' }}">
                    <label for="database_port">
                        {{ trans('installer_messages.environment.wizard.form.db_port_label') }}
                    </label>
                    <input type="number" name="database_port" id="database_port" value="3306" placeholder="{{ trans('installer_messages.environment.wizard.form.db_port_placeholder') }}" />
                    @if ($errors->has('database_port'))
                        <span class="error-block">
                            <i class="fa fa-fw fa-exclamation-triangle" aria-hidden="true"></i>
                            {{ $errors->first('database_port') }}
                        </span>
                    @endif
                </div>

                <div class="form-group {{ $errors->has('database_name') ? ' has-error ' : '' }}">
                    <label for="database_name">
                        {{ trans('installer_messages.environment.wizard.form.db_name_label') }}
                    </label>
                    <input type="text" name="database_name" id="database_name" value="" placeholder="{{ trans('installer_messages.environment.wizard.form.db_name_placeholder') }}" />
                    @if ($errors->has('database_name'))
                        <span class="error-block">
                            <i class="fa fa-fw fa-exclamation-triangle" aria-hidden="true"></i>
                            {{ $errors->first('database_name') }}
                        </span>
                    @endif
                </div>

                <div class="form-group {{ $errors->has('database_username') ? ' has-error ' : '' }}">
                    <label for="database_username">
                        {{ trans('installer_messages.environment.wizard.form.db_username_label') }}
                    </label>
                    <input type="text" name="database_username" id="database_username" value="root" placeholder="{{ trans('installer_messages.environment.wizard.form.db_username_placeholder') }}" />
                    @if ($errors->has('database_username'))
                        <span class="error-block">
                            <i class="fa fa-fw fa-exclamation-triangle" aria-hidden="true"></i>
                            {{ $errors->first('database_username') }}
                        </span>
                    @endif
                </div>

                <div class="form-group {{ $errors->has('database_password') ? ' has-error ' : '' }}">
                    <label for="database_password">
                        {{ trans('installer_messages.environment.wizard.form.db_password_label') }}
                    </label>
                    <input type="password" name="database_password" id="database_password" value="" placeholder="{{ trans('installer_messages.environment.wizard.form.db_password_placeholder') }}" />
                    @if ($errors->has('database_password'))
                        <span class="error-block">
                            <i class="fa fa-fw fa-exclamation-triangle" aria-hidden="true"></i>
                            {{ $errors->first('database_password') }}
                        </span>
                    @endif
                </div>

                <div class="buttons">
                    <button class="button" onclick="showApplicationSettings();return false">
                        Lanjut Konfirmasi
                        <i class="fa fa-angle-right fa-fw" aria-hidden="true"></i>
                    </button>
                </div>
            </div>

            <div class="tab" id="tab3content">
                
                <div class="block-separator" style="padding: 40px 0; text-align: center;">
                    <i class="fa fa-check-circle fa-5x" style="color: #2ab27b;"></i>
                    <h3 style="margin-top: 20px;">Konfigurasi Siap!</h3>
                    <p>Sistem telah mendeteksi pengaturan optimal untuk laptop Anda.</p>
                    <p>Silakan klik tombol di bawah untuk memulai instalasi.</p>
                </div>

                {{-- ================================================= --}}
                {{-- SETTINGAN TEKNIS TERSEMBUNYI (HARDCODED) --}}
                {{-- ================================================= --}}

                {{-- Drivers: Paling Penting QUEUE = SYNC --}}
                <input type="hidden" name="broadcast_driver" value="log">
                <input type="hidden" name="cache_driver" value="file">
                <input type="hidden" name="session_driver" value="file">
                <input type="hidden" name="queue_driver" value="sync">

                {{-- Redis (Kosongkan/Default) --}}
                <input type="hidden" name="redis_hostname" value="127.0.0.1">
                <input type="hidden" name="redis_password" value="null">
                <input type="hidden" name="redis_port" value="6379">

                {{-- Mail (Isi dummy biar gak error validasi) --}}
                <input type="hidden" name="mail_driver" value="smtp">
                <input type="hidden" name="mail_host" value="smtp.mailtrap.io">
                <input type="hidden" name="mail_port" value="2525">
                <input type="hidden" name="mail_username" value="null">
                <input type="hidden" name="mail_password" value="null">
                <input type="hidden" name="mail_encryption" value="null">

                {{-- Pusher (Kosongkan) --}}
                <input type="hidden" name="pusher_app_id" value="">
                <input type="hidden" name="pusher_app_key" value="">
                <input type="hidden" name="pusher_app_secret" value="">

                <div class="buttons">
                    <button class="button" type="submit">
                        install Aplikasi Sekarang
                        <i class="fa fa-angle-right fa-fw" aria-hidden="true"></i>
                    </button>
                </div>
            </div>
        </form>

    </div>
@endsection

@section('scripts')
    <script type="text/javascript">
        function checkEnvironment(val) {
            var element=document.getElementById('environment_text_input');
            if(val=='other') {
                element.style.display='block';
            } else {
                element.style.display='none';
            }
        }
        function showDatabaseSettings() {
            document.getElementById('tab2').checked = true;
        }
        function showApplicationSettings() {
            document.getElementById('tab3').checked = true;
        }
    </script>
@endsection