@extends('layouts.app')

@section('title', $app_setting['name'] . ' | ' . __('Company Profile'))

@section('content')
    <div class="app-main-outer">
        <div class="app-main-inner">
            <div class="page-title-actions px-3 d-flex">
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="{{ route('admin.dashboard') }}">{{ __('Dashboard') }}</a></li>
                        <li class="breadcrumb-item active" aria-current="page">{{ __('Company Profile') }}</li>
                    </ol>
                </nav>
            </div>

            <div class="row">
                <div class="col-12">
                    <div class="card">
                        <div class="card-body">
                            <h3 class="m-0 p-0">{{ __('Company Profile') }}</h3>
                            <p class="text-muted mb-0">
                                {{ __('Your name and logo — shown across your account, on your subdomain and any custom domain.') }}
                            </p>
                        </div>
                    </div>
                </div>
            </div>

            @if (session('success'))
                <div class="alert alert-success mt-3">{{ session('success') }}</div>
            @endif
            @if ($errors->any())
                <div class="alert alert-danger mt-3">
                    <ul class="m-0">
                        @foreach ($errors->all() as $error)
                            <li>{{ $error }}</li>
                        @endforeach
                    </ul>
                </div>
            @endif

            <form action="{{ route('company-profile.update') }}" method="POST" enctype="multipart/form-data">
                @csrf
                @method('PUT')

                <div class="row my-3">
                    <div class="col-12">
                        <div class="card">
                            <div class="card-body">
                                <div class="row">
                                    <div class="col-md-4 border-end mt-auto">
                                        <div class="mb-3">
                                            <img id="logoImagePreview" src="{{ $setting?->logoPath }}" class="w-100"
                                                style="max-height: 180px; border-radius:1rem; object-fit: contain">
                                        </div>
                                        <div>
                                            <label class="form-label">{{ __('Company logo') }} (JPG, PNG, SVG)</label>
                                            <input type="file" name="logo" accept="image/*" class="form-control"
                                                onchange="document.getElementById('logoImagePreview').src = URL.createObjectURL(this.files[0])">
                                            @error('logo')
                                                <p class="text-danger small mt-1">{{ $message }}</p>
                                            @enderror
                                        </div>
                                    </div>
                                    <div class="col-md-8">
                                        <label class="form-label">{{ __('Company name') }} <span class="text-danger">*</span></label>
                                        <input type="text" name="name" class="form-control" value="{{ old('name', $company->name) }}">
                                        @error('name')
                                            <p class="text-danger small mt-1">{{ $message }}</p>
                                        @enderror
                                        <p class="form-text">
                                            {{ __('This is your own name — it never changes what the platform is called for anyone else.') }}
                                        </p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <button type="submit" class="btn btn-primary">{{ __('Save changes') }}</button>
            </form>
        </div>
    </div>
@endsection
