 
<?php $__env->startSection('title', 'Tambah Produk'); ?> 
<?php $__env->startSection('content'); ?>

<style>
/* Biar jelas kelihatan disabled */
input:disabled {
    background-color: #e9ecef !important;
    cursor: not-allowed;
}
</style>

<div class="container">
    <form method="POST" action="<?php echo e(route('products.store')); ?>" enctype="multipart/form-data">
        <?php echo csrf_field(); ?>

        <div class="d-flex justify-content-between align-items-start flex-lg-row flex-column">

            
            <div class="text-center p-4 pt-0 d-flex flex-column">
                
                <label for="image" class="upload-box d-flex flex-column align-items-center justify-content-center">
                    <div id="image-preview">
                        <div id="image-instruction">Upload Photo</div>
                    </div>

                    <img id="preview-img" src="#" alt="Preview" style="display:none; max-width:200px;">

                    <div id="file-name"></div>
                </label>

                <input 
                    type="file" 
                    name="image" 
                    id="image" 
                    class="d-none" 
                    accept="image/*"
                    onchange="previewImage(event)"
                >

                <?php $__errorArgs = ['image'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                    <div class="text-danger mt-1"><?php echo e($message); ?></div>
                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>

                <button type="button" id="remove-image-btn"
                    class="btn btn-outline-danger remove-btn"
                    style="display:none;"
                    onclick="removeImage()"
                >
                    Remove File
                </button>
            </div>

            
            <div class="w-100">

                <?php if (isset($component)) { $__componentOriginal262894a2c291df91ae9f7b925bf8a923 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal262894a2c291df91ae9f7b925bf8a923 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.input-text','data' => ['inRowLabel' => 'Nama Produk','name' => 'name','required' => true,'placeholder' => 'Masukkan nama produk','value' => old('name'),'errorMessage' => $errors->first('name')]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('input-text'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['inRowLabel' => 'Nama Produk','name' => 'name','required' => true,'placeholder' => 'Masukkan nama produk','value' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(old('name')),'errorMessage' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($errors->first('name'))]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal262894a2c291df91ae9f7b925bf8a923)): ?>
<?php $attributes = $__attributesOriginal262894a2c291df91ae9f7b925bf8a923; ?>
<?php unset($__attributesOriginal262894a2c291df91ae9f7b925bf8a923); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal262894a2c291df91ae9f7b925bf8a923)): ?>
<?php $component = $__componentOriginal262894a2c291df91ae9f7b925bf8a923; ?>
<?php unset($__componentOriginal262894a2c291df91ae9f7b925bf8a923); ?>
<?php endif; ?>

                <?php if (isset($component)) { $__componentOriginal262894a2c291df91ae9f7b925bf8a923 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal262894a2c291df91ae9f7b925bf8a923 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.input-text','data' => ['inRowLabel' => 'Harga','name' => 'price','required' => true,'placeholder' => 'Masukkan harga produk','value' => old('price'),'errorMessage' => $errors->first('price')]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('input-text'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['inRowLabel' => 'Harga','name' => 'price','required' => true,'placeholder' => 'Masukkan harga produk','value' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(old('price')),'errorMessage' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($errors->first('price'))]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal262894a2c291df91ae9f7b925bf8a923)): ?>
<?php $attributes = $__attributesOriginal262894a2c291df91ae9f7b925bf8a923; ?>
<?php unset($__attributesOriginal262894a2c291df91ae9f7b925bf8a923); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal262894a2c291df91ae9f7b925bf8a923)): ?>
<?php $component = $__componentOriginal262894a2c291df91ae9f7b925bf8a923; ?>
<?php unset($__componentOriginal262894a2c291df91ae9f7b925bf8a923); ?>
<?php endif; ?>

                <?php if (isset($component)) { $__componentOriginal0005bf01aa83ec4ca92674161039a6ca = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal0005bf01aa83ec4ca92674161039a6ca = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.input-select','data' => ['inRowLabel' => 'Tersedia untuk Reseller','name' => 'available_for_reseller','options' => ['0' => 'Tidak', '1' => 'Ya'],'value' => old('available_for_reseller', 0)]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('input-select'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['inRowLabel' => 'Tersedia untuk Reseller','name' => 'available_for_reseller','options' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(['0' => 'Tidak', '1' => 'Ya']),'value' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(old('available_for_reseller', 0))]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal0005bf01aa83ec4ca92674161039a6ca)): ?>
<?php $attributes = $__attributesOriginal0005bf01aa83ec4ca92674161039a6ca; ?>
<?php unset($__attributesOriginal0005bf01aa83ec4ca92674161039a6ca); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal0005bf01aa83ec4ca92674161039a6ca)): ?>
<?php $component = $__componentOriginal0005bf01aa83ec4ca92674161039a6ca; ?>
<?php unset($__componentOriginal0005bf01aa83ec4ca92674161039a6ca); ?>
<?php endif; ?>

                <?php if (isset($component)) { $__componentOriginal262894a2c291df91ae9f7b925bf8a923 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal262894a2c291df91ae9f7b925bf8a923 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.input-text','data' => ['inRowLabel' => 'Harga Reseller','name' => 'reseller_price','placeholder' => 'Masukkan harga reseller','value' => old('reseller_price'),'errorMessage' => $errors->first('reseller_price')]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('input-text'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['inRowLabel' => 'Harga Reseller','name' => 'reseller_price','placeholder' => 'Masukkan harga reseller','value' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(old('reseller_price')),'errorMessage' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($errors->first('reseller_price'))]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal262894a2c291df91ae9f7b925bf8a923)): ?>
<?php $attributes = $__attributesOriginal262894a2c291df91ae9f7b925bf8a923; ?>
<?php unset($__attributesOriginal262894a2c291df91ae9f7b925bf8a923); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal262894a2c291df91ae9f7b925bf8a923)): ?>
<?php $component = $__componentOriginal262894a2c291df91ae9f7b925bf8a923; ?>
<?php unset($__componentOriginal262894a2c291df91ae9f7b925bf8a923); ?>
<?php endif; ?>

                <?php if (isset($component)) { $__componentOriginal112ecadca39af188988f468fd61b41b6 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal112ecadca39af188988f468fd61b41b6 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.input-text-area','data' => ['inRowLabel' => 'Deskripsi','name' => 'description','rows' => '3','required' => true,'placeholder' => 'Masukkan deskripsi produk','errorMessage' => $errors->first('description')]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('input-text-area'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['inRowLabel' => 'Deskripsi','name' => 'description','rows' => '3','required' => true,'placeholder' => 'Masukkan deskripsi produk','errorMessage' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($errors->first('description'))]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal112ecadca39af188988f468fd61b41b6)): ?>
<?php $attributes = $__attributesOriginal112ecadca39af188988f468fd61b41b6; ?>
<?php unset($__attributesOriginal112ecadca39af188988f468fd61b41b6); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal112ecadca39af188988f468fd61b41b6)): ?>
<?php $component = $__componentOriginal112ecadca39af188988f468fd61b41b6; ?>
<?php unset($__componentOriginal112ecadca39af188988f468fd61b41b6); ?>
<?php endif; ?>
                
                <div class="d-flex justify-content-between pe-2 mt-4">
                    <?php if (isset($component)) { $__componentOriginalb04da7a8feb93a7268b6e0eef6b32739 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginalb04da7a8feb93a7268b6e0eef6b32739 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.gold-button','data' => ['type' => 'button','onclick' => 'window.location.href=\''.e(route('products.index')).'\'']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('gold-button'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['type' => 'button','onclick' => 'window.location.href=\''.e(route('products.index')).'\'']); ?>
                        <i class="bi bi-arrow-left"></i> Back
                     <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginalb04da7a8feb93a7268b6e0eef6b32739)): ?>
<?php $attributes = $__attributesOriginalb04da7a8feb93a7268b6e0eef6b32739; ?>
<?php unset($__attributesOriginalb04da7a8feb93a7268b6e0eef6b32739); ?>
<?php endif; ?>
<?php if (isset($__componentOriginalb04da7a8feb93a7268b6e0eef6b32739)): ?>
<?php $component = $__componentOriginalb04da7a8feb93a7268b6e0eef6b32739; ?>
<?php unset($__componentOriginalb04da7a8feb93a7268b6e0eef6b32739); ?>
<?php endif; ?>

                    <?php if (isset($component)) { $__componentOriginald0f1fd2689e4bb7060122a5b91fe8561 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.button','data' => ['type' => 'submit']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('button'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['type' => 'submit']); ?>
                        Add Product
                     <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561)): ?>
<?php $attributes = $__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561; ?>
<?php unset($__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561); ?>
<?php endif; ?>
<?php if (isset($__componentOriginald0f1fd2689e4bb7060122a5b91fe8561)): ?>
<?php $component = $__componentOriginald0f1fd2689e4bb7060122a5b91fe8561; ?>
<?php unset($__componentOriginald0f1fd2689e4bb7060122a5b91fe8561); ?>
<?php endif; ?>
                </div>

            </div>

        </div>
    </form>
</div>

<script>
function previewImage(event) {
    const input = event.target;
    const preview = document.getElementById('preview-img');
    const fileName = document.getElementById('file-name');
    const instruction = document.getElementById('image-instruction');
    const removeBtn = document.getElementById('remove-image-btn');

    if (input.files && input.files[0]) {
        const reader = new FileReader();
        reader.onload = e => {
            preview.src = e.target.result;
            preview.style.display = 'block';
        };
        reader.readAsDataURL(input.files[0]);

        fileName.textContent = input.files[0].name;
        instruction.style.display = 'none';
        removeBtn.style.display = 'inline-block';
    }
}

function removeImage() {
    const input = document.getElementById('image');
    input.value = "";
    document.getElementById('preview-img').style.display = 'none';
    document.getElementById('file-name').textContent = '';
    document.getElementById('image-instruction').style.display = 'block';
    document.getElementById('remove-image-btn').style.display = 'none';
}

document.addEventListener('DOMContentLoaded', function () {

    const availableSelect = document.querySelector('[name="available_for_reseller"]');
    const resellerPriceInput = document.querySelector('[name="reseller_price"]');

    function toggleResellerPrice() {
        if (availableSelect.value === '1') {
            resellerPriceInput.disabled = false;
            resellerPriceInput.required = true;
        } else {
            resellerPriceInput.disabled = true;
            resellerPriceInput.required = false;
            resellerPriceInput.value = '';
        }
    }

    toggleResellerPrice();

    availableSelect.addEventListener('change', toggleResellerPrice);
});
</script>

<?php $__env->stopSection(); ?>

<?php echo $__env->make('layout.main', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\PAW\PiaZhang\resources\views/products/create.blade.php ENDPATH**/ ?>