@extends('layouts.app')
@section('title','File Document')
@section('crumbs','<a href="'.route('docs-library.index').'">Document Library</a> · <b>File document</b>')
@section('content')
<div class="card" style="max-width:640px"><div class="card-h"><h2>＋ File document</h2></div>
<div class="card-b">
<form method="POST" action="{{ route('docs-library.store') }}" enctype="multipart/form-data">
@csrf
@if($errors->any())<div class="flash err">✕ {{ $errors->first() }}</div>@endif
<div class="frow">
<div class="fld c6"><label>File (max 20 MB — pdf, office, images, csv, zip)</label><input type="file" name="file" required></div>
<div class="fld c6"><label>Display name <small class="muted">(blank = original filename; re-using a name on the same record saves a new version)</small></label><input type="text" name="file_name" value="{{ old('file_name') }}" placeholder="e.g. EPA permit 2026.pdf"></div>
<div class="fld c6"><label>Link to</label><select name="attachable_type" id="ownerType">
<option value="unfiled">— Unfiled (general library) —</option>
@foreach($owners as $class => $o)<option value="{{ $class }}" {{ old('attachable_type')===$class?'selected':'' }}>{{ $o[0] }}</option>@endforeach
</select></div>
<div class="fld c6" id="ownerIdWrap"><label>Record ID <small class="muted">(e.g. customer # or invoice #)</small></label><input type="number" min="1" name="attachable_id" value="{{ old('attachable_id') }}"></div>
</div>
<div style="margin-top:12px;display:flex;gap:8px">
<button class="btn">Upload & file</button>
<a class="btn btn-ghost" href="{{ route('docs-library.index') }}">Cancel</a>
</div>
</form>
</div></div>
<script>
(function(){var t=document.getElementById('ownerType'),w=document.getElementById('ownerIdWrap');
function sync(){w.style.display=t.value==='unfiled'?'none':'';}t.addEventListener('change',sync);sync();})();
</script>
@endsection
