<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * Talent — roster listing and individual talent profiles.
 */
#[\AllowDynamicProperties]
class Talent extends Public_Controller {

	public function __construct()
	{
		parent::__construct();
		$this->load->model(array('talent_model'));
	}

	/** Full roster (client-side filterable). */
	public function index()
	{
		$this->meta(array(
			'title'       => 'Talent Roster — Bloom Iris Agency',
			'description' => 'Models, influencers, creatives and stylists represented by Bloom Iris Agency.',
		));
		$this->render('talent/index', array(
			'talent'     => $this->talent_model->active(),
			'categories' => $this->config->item('talent_categories'),
			'counts'     => $this->talent_model->category_counts(),
			'active_cat' => 'all',
		));
	}

	/** Roster filtered by category. */
	public function category($slug)
	{
		$categories = $this->config->item('talent_categories');
		if ( ! isset($categories[$slug])) show_404();

		$this->meta(array('title' => $categories[$slug].' — Talent — Bloom Iris Agency'));
		$this->render('talent/index', array(
			'talent'     => $this->talent_model->active($slug),
			'categories' => $categories,
			'counts'     => $this->talent_model->category_counts(),
			'active_cat' => $slug,
		));
	}

	/** Single talent profile. */
	public function detail($slug)
	{
		$talent = $this->talent_model->by_slug($slug);
		if ( ! $talent) show_404();

		$categories = $this->config->item('talent_categories');

		$this->meta(array(
			'title'       => $talent['name'].' — '.($categories[$talent['category']] ?? 'Talent').' — Bloom Iris Agency',
			'description' => excerpt($talent['bio'], 30),
			'image'       => upload_url($talent['photo']),
		));

		$this->render('talent/detail', array(
			'talent'     => $talent,
			'gallery'    => decode_json($talent['gallery']),
			'stats'      => decode_json($talent['stats']),
			'socials'    => decode_json($talent['socials']),
			'related'    => $this->talent_model->related($talent['category'], $talent['id'], 4),
			'categories' => $categories,
		));
	}
}
