<?php
// app/Http/Controllers/CustomScriptController.php

namespace App\Http\Controllers;

use App\Services\CustomScriptService;
use Illuminate\Http\Request;

class CustomScriptController extends Controller
{
    protected $customScriptService;

    public function __construct(CustomScriptService $customScriptService)
    {
        $this->customScriptService = $customScriptService;
    }

    public function index()
    {
        $customScripts = $this->customScriptService->getAllCustomScripts();
        return view('custom_scripts.index', compact('customScripts'));
    }

    public function store(Request $request)
    {
        $request->validate([
            'name' => 'required|string|max:255',
            'content' => 'required|string',
        ]);

        $this->customScriptService->createCustomScript([
            'name' => $request->name,
            'content' => $request->content,
        ]);

        return redirect()->route('custom_scripts.index')
            ->with('success', 'Custom script berhasil disimpan.');
    }
}