<?php
if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly.
}

class Manfiet_Expense_Tracker_Widget_Expense_Entry extends \Elementor\Widget_Base {

    public function get_name() {
        return 'manfiet-expense-entry';
    }

    public function get_title() {
        return esc_html__('Expense Entry', 'manfi-expense-tracker');
    }

    public function get_icon() {
        return 'eicon-form-horizontal';
    }

    public function get_categories() {
        return ['manfi-expense-tracker'];
    }

    public function get_style_depends() {
        return ['manfiet-expense-frontend-style'];
    }

    protected function register_controls() {
        // No custom controls needed for this widget.
    }

    protected function render() {
        if (!is_user_logged_in()) {
            echo '<p>' . esc_html__('You need to be logged in to track your expenses.', 'manfi-expense-tracker') . '</p>';
            return;
        }

        if (!current_user_can('read')) {
            echo '<p>' . esc_html__('You do not have permission to access this tracker.', 'manfi-expense-tracker') . '</p>';
            return;
        }

        \Manfiet_Expense_Tracker_Elementor::enqueue_frontend_assets();

        // If in Elementor Editor, render a beautiful mockup preview
        if (class_exists('\Elementor\Plugin') && \Elementor\Plugin::$instance->editor->is_edit_mode()) {
            $currency_symbol = class_exists('Manfiet_Expense_Tracker_Settings') ? Manfiet_Expense_Tracker_Settings::get_current_currency_symbol() : '$';
            ?>
            <div class="manfiet-card manfiet-expense-form-card" style="box-shadow: var(--manfiet-card-shadow);">
                <h3 class="manfiet-section-title">
                    <?php esc_html_e('Add New Expense', 'manfi-expense-tracker'); ?>
                    <span style="font-size: 11px; font-weight: normal; color: #94a3b8; margin-left: 8px;">(<?php esc_html_e('Editor Preview', 'manfi-expense-tracker'); ?>)</span>
                </h3>
                <div class="manfiet-expense-form-layout">
                    <!-- Left Column: Core Fields -->
                    <div class="manfiet-expense-primary-fields">
                        <div class="manfiet-field">
                            <label class="manfiet-label"><?php esc_html_e('Category', 'manfi-expense-tracker'); ?></label>
                            <select class="manfiet-input" disabled>
                                <option><?php esc_html_e('Select a category', 'manfi-expense-tracker'); ?></option>
                                <option>Food</option>
                                <option>Travel</option>
                                <option>Utilities</option>
                                <option>Rent</option>
                            </select>
                        </div>
                        <div class="manfiet-field">
                            <label class="manfiet-label"><?php esc_html_e('Amount', 'manfi-expense-tracker'); ?> (<?php echo esc_html($currency_symbol); ?>)</label>
                            <input type="number" placeholder="0.00" class="manfiet-input" disabled />
                        </div>
                        <div class="manfiet-field">
                            <label class="manfiet-label"><?php esc_html_e('Date', 'manfi-expense-tracker'); ?></label>
                            <input type="date" value="<?php echo esc_attr(gmdate('Y-m-d')); ?>" class="manfiet-input" disabled />
                        </div>
                        <div class="manfiet-field">
                            <label class="manfiet-label"><?php esc_html_e('Recurring Interval', 'manfi-expense-tracker'); ?></label>
                            <select class="manfiet-input" disabled>
                                <option><?php esc_html_e('One-time', 'manfi-expense-tracker'); ?></option>
                                <option><?php esc_html_e('Daily', 'manfi-expense-tracker'); ?></option>
                                <option><?php esc_html_e('Weekly', 'manfi-expense-tracker'); ?></option>
                                <option><?php esc_html_e('Monthly', 'manfi-expense-tracker'); ?></option>
                                <option><?php esc_html_e('Yearly', 'manfi-expense-tracker'); ?></option>
                            </select>
                        </div>
                        <div class="manfiet-field" style="grid-column: span 2;">
                            <label class="manfiet-label"><?php esc_html_e('Remark', 'manfi-expense-tracker'); ?></label>
                            <textarea placeholder="<?php esc_attr_e('Optional notes...', 'manfi-expense-tracker'); ?>" class="manfiet-input" rows="2" disabled></textarea>
                        </div>
                    </div>

                    <!-- Right Column: Tags Chips Selector -->
                    <div class="manfiet-field">
                        <label class="manfiet-label"><?php esc_html_e('Select Tags', 'manfi-expense-tracker'); ?></label>
                        <div class="manfiet-tag-chips-wrapper">
                            <div class="manfiet-tag-chips">
                                <button type="button" class="manfiet-tag-chip manfiet-tag-chip-selected" disabled>
                                    Food <span class="manfiet-tag-chip-check">✓</span>
                                </button>
                                <button type="button" class="manfiet-tag-chip" disabled>
                                    Travel
                                </button>
                                <button type="button" class="manfiet-tag-chip" disabled>
                                    Office
                                </button>
                                <button type="button" class="manfiet-tag-chip" disabled>
                                    Personal
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="manfiet-form-actions">
                    <button type="button" class="manfiet-btn-save-expense" disabled>
                        <?php esc_html_e('Save Expense', 'manfi-expense-tracker'); ?>
                    </button>
                </div>
            </div>
            <?php
        } else {
            echo '<div class="manfi-expense-tracker-mount" data-view="expense-entry"></div>';
        }
    }
}
