<?php

namespace App\Http\Controllers\Eventmie;

use Illuminate\Http\Request;
use Auth;
use Facades\Classiebit\Eventmie\Eventmie;
use App\Models\User;
use Classiebit\Eventmie\Http\Controllers\TagsController as BaseTagsController;

class TagsController extends BaseTagsController
{
    public function __construct()
    {
        parent::__construct();
        $this->user         = new User;
    }

     public function form($id = null, $view = 'vendor.eventmie-pro.tags.form', $extra = [])
    {
        // get prifex from eventmie config
        $path = false;
        if(!empty(config('eventmie.route.prefix')))
            $path = config('eventmie.route.prefix');

        $id     = (int) $id;
        $event  = [];
        
        $organiser_id    = Auth::id();

        return Eventmie::view($view, compact('organiser_id', 'path', 'extra'));
    }

    // get tags for particular organiser
    public function tags(Request $request)
    {
        // if logged in user is admin
        $this->is_admin($request);

        $params = [
            'organizer_id' => $this->organiser_id,
            'search' => $request->search,
            'per_page' => $request->per_page ?? 10, // Default to 10 if not provided
        ];

        $tags  = $this->user->get_tags($params);

        if(empty($tags))
        {
            return response()->json(['status' => false]);    
        }

        return response()->json(['status' => true, 'tags' => $tags->jsonSerialize() ]);
    }
}
