<?php

namespace App\Http\Controllers\Agency;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class AgencyPagePreviewController extends Controller
{
    protected $pageService;

    public function __construct(\App\Services\Agency\AgencyPageService $pageService)
    {
        $this->pageService = $pageService;
    }

    public function preview()
    {
        $agency = auth()->user()->agency;

        if (!$agency) {
            abort(403);
        }

        $page = $agency->agencyPage;

        if (!$page) {
            abort(404, 'Sayfa bulunamadı');
        }

        $theme = $page->theme;

        // Theme settings compile
        $themeSettings = $this->pageService->getCompiledThemeSettings($page);

        // Draft sections
        $sections = $page->sections()->active()->ordered()->get();

        return view('page.agency.index', compact('agency', 'page', 'theme', 'themeSettings', 'sections'));
    }
}
