<?php
    $selectedTechnologies = collect(old('technologies', isset($project) ? $project->technologies->pluck('id')->all() : []))
        ->map(function ($id) {
            return (string) $id;
        })
        ->all();

    $statusValue = old('status', isset($project) ? strtolower((string) $project->status) : 'active');
    $showTechnologyQuickAdd = $showTechnologyQuickAdd ?? false;
    $allowTechnologyDelete = $allowTechnologyDelete ?? false;
?>

<div class="mb-4">
    <label for="project_name" class="form-label fw-bold text-dark mb-2">Project Name</label>
    <div class="input-group">
        <span class="input-group-text bg-light border-0">
            <i class="bi bi-kanban text-secondary"></i>
        </span>
        <input
            type="text"
            name="project_name"
            id="project_name"
            class="form-control bg-light border-0 <?php $__errorArgs = ['project_name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
            placeholder="e.g. Portfolio Management Dashboard"
            value="<?php echo e(old('project_name', $project->project_name ?? '')); ?>"
            required
            style="padding: 0.8rem;"
        >
    </div>
    <?php $__errorArgs = ['project_name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
        <div class="invalid-feedback d-block mt-2"><?php echo e($message); ?></div>
    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
</div>

<div class="mb-4">
    <label for="short_description" class="form-label fw-bold text-dark mb-2">Short Description</label>
    <div class="input-group">
        <span class="input-group-text bg-light border-0 align-items-start pt-3">
            <i class="bi bi-text-paragraph text-secondary"></i>
        </span>
        <textarea
            name="short_description"
            id="short_description"
            rows="5"
            class="form-control bg-light border-0 <?php $__errorArgs = ['short_description'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
            placeholder="Write a clean summary of what this project does and why it matters."
            required
        ><?php echo e(old('short_description', $project->short_description ?? '')); ?></textarea>
    </div>
    <?php $__errorArgs = ['short_description'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
        <div class="invalid-feedback d-block mt-2"><?php echo e($message); ?></div>
    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
</div>

<div class="row g-4 mb-4">
    <div class="col-md-6">
        <label for="github_link" class="form-label fw-bold text-dark mb-2">GitHub Link</label>
        <div class="input-group">
            <span class="input-group-text bg-light border-0">
                <i class="bi bi-github text-secondary"></i>
            </span>
            <input
                type="url"
                name="github_link"
                id="github_link"
                class="form-control bg-light border-0 <?php $__errorArgs = ['github_link'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                placeholder="https://github.com/username/project"
                value="<?php echo e(old('github_link', $project->github_link ?? '')); ?>"
            >
        </div>
        <?php $__errorArgs = ['github_link'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
            <div class="invalid-feedback d-block mt-2"><?php echo e($message); ?></div>
        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
    </div>

    <div class="col-md-6">
        <label for="live_demo_link" class="form-label fw-bold text-dark mb-2">Live Demo Link</label>
        <div class="input-group">
            <span class="input-group-text bg-light border-0">
                <i class="bi bi-box-arrow-up-right text-secondary"></i>
            </span>
            <input
                type="url"
                name="live_demo_link"
                id="live_demo_link"
                class="form-control bg-light border-0 <?php $__errorArgs = ['live_demo_link'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                placeholder="https://your-live-project.com"
                value="<?php echo e(old('live_demo_link', $project->live_demo_link ?? '')); ?>"
            >
        </div>
        <?php $__errorArgs = ['live_demo_link'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
            <div class="invalid-feedback d-block mt-2"><?php echo e($message); ?></div>
        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
    </div>
</div>

<div class="row g-4 mb-4">
    <div class="col-lg-5">
        <label for="status" class="form-label fw-bold text-dark mb-2">Project Status</label>
        <div class="input-group project-status-control" data-project-status-control style="cursor: pointer; user-select: none;">
            <span class="input-group-text border-0">
                <i class="bi bi-toggle-on project-status-icon"></i>
            </span>
            <input type="hidden" name="status" id="status" value="<?php echo e($statusValue); ?>">
            <div class="form-control border-0 project-status-select d-flex align-items-center <?php $__errorArgs = ['status'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>">
                <span class="status-text"><?php echo e($statusValue === 'active' ? 'Active' : 'Inactive'); ?></span>
            </div>
        </div>
        <?php $__errorArgs = ['status'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
            <div class="invalid-feedback d-block mt-2"><?php echo e($message); ?></div>
        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
    </div>

    <div class="col-lg-7">
        <label for="image" class="form-label fw-bold text-dark mb-2">Project Image</label>

        <?php if(isset($project) && !empty($project->image)): ?>
            <div class="current-image-card mb-3">
                <img
                    src="<?php echo e(asset('storage/' . $project->image)); ?>"
                    alt="<?php echo e($project->project_name); ?>"
                    class="current-image-thumb"
                >
                <div>
                    <span class="current-image-label">Current Preview</span>
                    <p class="text-secondary small mb-0">Upload a new image only if you want to replace the existing one.</p>
                </div>
            </div>
        <?php endif; ?>

        <div class="upload-container bg-light rounded-4 p-4 text-center border-2 border-dashed border-secondary-subtle">
            <i class="bi bi-image-fill text-primary fs-1 mb-3 d-block"></i>
            <p class="text-dark fw-semibold mb-1"><?php echo e(isset($project) ? 'Upload a replacement image' : 'Choose a project preview image'); ?></p>
            <p class="text-secondary small mb-0" id="project-image-name">
                <?php echo e(isset($project) ? 'Leave this empty to keep the current image.' : 'JPG, PNG, or WEBP up to 2MB.'); ?>

            </p>
            <input
                type="file"
                name="image"
                id="image"
                class="form-control <?php $__errorArgs = ['image'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                accept=".jpg,.jpeg,.png,.webp"
            >
        </div>
        <?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="invalid-feedback d-block mt-2"><?php echo e($message); ?></div>
        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
    </div>
</div>

<div class="mb-4">
    <div class="d-flex align-items-center justify-content-between gap-3 mb-2 flex-wrap">
        <label class="form-label fw-bold text-dark mb-0">Project Technologies</label>
        <div class="d-flex align-items-center gap-2 ms-auto">
            <span class="small text-secondary">Choose at least one</span>
            <?php if($showTechnologyQuickAdd): ?>
                <button
                    type="button"
                    class="btn btn-outline-primary btn-sm rounded-3 px-3 technology-add-btn"
                    data-bs-toggle="modal"
                    data-bs-target="#addTechnologyModal"
                >
                    <i class="bi bi-tags me-1"></i> + Add Technology
                </button>
            <?php endif; ?>
        </div>
    </div>

    <?php echo $__env->make('projects._technology_options', [
        'technologies' => $technologies,
        'selectedTechnologies' => $selectedTechnologies,
        'allowTechnologyDelete' => $allowTechnologyDelete,
    ], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>

    <?php $__errorArgs = ['technologies'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
        <div class="invalid-feedback d-block mt-2"><?php echo e($message); ?></div>
    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
</div>
<?php /**PATH C:\laragon\www\portfolio\resources\views/projects/_form.blade.php ENDPATH**/ ?>