<?php

namespace MODELORA\Elementor;

if (! defined('ABSPATH')) {
    exit;
}

class WidgetModelViewer extends \Elementor\Widget_Base
{
    public function get_name(): string
    {
        return 'modelora_model_viewer';
    }

    public function get_title(): string
    {
        return __('Modelora Model Viewer', 'modelora-3d-product-viewer');
    }

    public function get_icon(): string
    {
        return 'eicon-product-images';
    }

    public function get_categories(): array
    {
        return ['general'];
    }

    protected function register_controls(): void
    {
        $this->start_controls_section('content_section', ['label' => __('Viewer', 'modelora-3d-product-viewer')]);

        $this->add_control('model_id', [
            'label' => __('Model ID', 'modelora-3d-product-viewer'),
            'type' => \Elementor\Controls_Manager::NUMBER,
            'default' => 0,
        ]);

        $this->add_control('preset', [
            'label' => __('Preset', 'modelora-3d-product-viewer'),
            'type' => \Elementor\Controls_Manager::SELECT,
            'default' => 'studio',
            'options' => [
                'studio' => __('Studio', 'modelora-3d-product-viewer'),
                'outdoor' => __('Outdoor', 'modelora-3d-product-viewer'),
                'dark' => __('Dark', 'modelora-3d-product-viewer'),
            ],
        ]);

        $this->end_controls_section();
    }

    protected function render(): void
    {
        $settings = $this->get_settings_for_display();
        echo do_shortcode('[modelora_viewer id="' . (int) $settings['model_id'] . '" preset="' . esc_attr($settings['preset']) . '"]');
    }
}

