<?php

namespace Src\Common\Laravel\Controllers;

use Illuminate\Http\Request;
use Src\Common\Application\JoditFilesBrowser;

class JoditFilesBrowserController
{

    protected JoditFilesBrowser $filesBrowser;

    public function __construct()
    {
        $this->filesBrowser = new JoditFilesBrowser();
    }

    public function upload(Request $request)
    {
        $data = $request->all();
        return $this->filesBrowser->upload($data);
    }

    public function create(Request $request)
    {
        $data = $request->all();
        return $this->filesBrowser->create($data);
    }

    public function move(Request $request) {}

    public function remove(Request $request) {}

    public function items(Request $request)
    {
        $data = $request->all();
        return $this->filesBrowser->items($data);
    }

    public function tree(Request $request)
    {
        return [];
    }

    public function folder(Request $request)
    {
        $data = $request->all();
        return $this->filesBrowser->folder($data);
    }

    public function ajax(Request $request)
    {
        $data = $request->all();
        $action = $data['action'];

        switch ($action) {
            case 'permissions':
                return $this->filesBrowser->getPermissions();
            case 'folderRemove':
                return $this->filesBrowser->folderRemove($data);
            case 'folderRename':
                return $this->filesBrowser->folderRename($data);
            case 'fileRemove':
                return $this->filesBrowser->fileRemove($data);
        }
    }
}
