<?php
/**
 * Plugin Name: CF Accounting Calculator
 * Description: Interactive "Time & Cost of Accounting" calculator for Community Financials.
 * Version: 1.0.0
 * Author: Bowden Works
 */

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

function cfac_enqueue_assets() {
    global $post;
    if ( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'cf_accounting_calculator' ) ) {
        wp_enqueue_style(
            'cfac-style',
            plugin_dir_url( __FILE__ ) . 'cfac-style.css',
            array(),
            '1.0.0'
        );
        wp_enqueue_script(
            'cfac-script',
            plugin_dir_url( __FILE__ ) . 'cfac-script.js',
            array(),
            '1.0.0',
            true
        );
    }
}
add_action( 'wp_enqueue_scripts', 'cfac_enqueue_assets' );

function cfac_render_calculator() {
    ob_start();
    ?>
    <div class="cfac-calculator">

        <div class="cfac-header">
            <h2 class="cfac-title">Time &amp; Cost of Accounting Calculator</h2>
            <p class="cfac-subtitle">Use this calculator to see how much time and money you are spending on HOA &amp; Condo accounting.</p>
        </div>

        <!-- Section 1: Time Tracking -->
        <div class="cfac-section">
            <h3 class="cfac-section-title">
                <span class="cfac-step-number">1</span>
                How much time do you spend?
            </h3>

            <div class="cfac-toggle-group">
                <label class="cfac-toggle-label">
                    <input type="radio" name="cfac_mode" value="self" checked>
                    <span>I do the accounting myself</span>
                </label>
                <label class="cfac-toggle-label">
                    <input type="radio" name="cfac_mode" value="others">
                    <span>Others handle accounting, but I deal with issues</span>
                </label>
            </div>

            <!-- Self mode: single input -->
            <div class="cfac-mode-panel" id="cfac-mode-self">
                <div class="cfac-input-row">
                    <label for="cfac_self_hours">Total hours per month you spend on accounting</label>
                    <div class="cfac-input-wrap">
                        <input type="number" id="cfac_self_hours" class="cfac-input" min="0" step="0.5" placeholder="0">
                        <span class="cfac-input-unit">hrs/mo</span>
                    </div>
                </div>
            </div>

            <!-- Others mode: detailed breakdown -->
            <div class="cfac-mode-panel" id="cfac-mode-others" style="display:none;">
                <p class="cfac-mode-desc">Estimate the monthly hours you spend on each of these accounting-related tasks:</p>

                <div class="cfac-input-row">
                    <label for="cfac_errors_review">Reviewing &amp; documenting errors</label>
                    <div class="cfac-input-wrap">
                        <input type="number" id="cfac_errors_review" class="cfac-input cfac-detail-input" min="0" step="0.5" placeholder="0">
                        <span class="cfac-input-unit">hrs/mo</span>
                    </div>
                </div>

                <div class="cfac-input-row">
                    <label for="cfac_errors_correct">Working to correct errors</label>
                    <div class="cfac-input-wrap">
                        <input type="number" id="cfac_errors_correct" class="cfac-input cfac-detail-input" min="0" step="0.5" placeholder="0">
                        <span class="cfac-input-unit">hrs/mo</span>
                    </div>
                </div>

                <div class="cfac-input-row">
                    <label for="cfac_followup">Following up on calls &amp; emails</label>
                    <div class="cfac-input-wrap">
                        <input type="number" id="cfac_followup" class="cfac-input cfac-detail-input" min="0" step="0.5" placeholder="0">
                        <span class="cfac-input-unit">hrs/mo</span>
                    </div>
                </div>

                <div class="cfac-input-row">
                    <label for="cfac_payments">Handling owner payments</label>
                    <div class="cfac-input-wrap">
                        <input type="number" id="cfac_payments" class="cfac-input cfac-detail-input" min="0" step="0.5" placeholder="0">
                        <span class="cfac-input-unit">hrs/mo</span>
                    </div>
                </div>

                <div class="cfac-input-row">
                    <label for="cfac_vendors">Vendor payments, late/unpaid bills &amp; vendor calls</label>
                    <div class="cfac-input-wrap">
                        <input type="number" id="cfac_vendors" class="cfac-input cfac-detail-input" min="0" step="0.5" placeholder="0">
                        <span class="cfac-input-unit">hrs/mo</span>
                    </div>
                </div>

                <div class="cfac-input-row">
                    <label for="cfac_late">Dealing with or paying late charges</label>
                    <div class="cfac-input-wrap">
                        <input type="number" id="cfac_late" class="cfac-input cfac-detail-input" min="0" step="0.5" placeholder="0">
                        <span class="cfac-input-unit">hrs/mo</span>
                    </div>
                </div>

                <div class="cfac-input-row">
                    <label for="cfac_recreating">Recreating accounting or reports yourself</label>
                    <div class="cfac-input-wrap">
                        <input type="number" id="cfac_recreating" class="cfac-input cfac-detail-input" min="0" step="0.5" placeholder="0">
                        <span class="cfac-input-unit">hrs/mo</span>
                    </div>
                </div>
            </div>

            <div class="cfac-subtotal">
                <div class="cfac-subtotal-row">
                    <span>Total monthly hours:</span>
                    <strong id="cfac-total-hours-monthly">0</strong>
                </div>
                <div class="cfac-subtotal-row">
                    <span>Total annual hours:</span>
                    <strong id="cfac-total-hours-annual">0</strong>
                </div>
            </div>
        </div>

        <!-- Section 2: Value of Time -->
        <div class="cfac-section">
            <h3 class="cfac-section-title">
                <span class="cfac-step-number">2</span>
                What is your time worth?
            </h3>
            <p class="cfac-callout">Time is our most precious commodity &mdash; once you spend it, you can&rsquo;t get it back.</p>

            <div class="cfac-value-prompts">
                <p>Consider: How much do you value your time if you put an hourly amount to it? Or, what was/is your hourly pay?</p>
            </div>

            <div class="cfac-input-row">
                <label for="cfac_hourly_rate">Your hourly rate</label>
                <div class="cfac-input-wrap">
                    <span class="cfac-input-prefix">$</span>
                    <input type="number" id="cfac_hourly_rate" class="cfac-input cfac-input-dollar" min="0" step="1" placeholder="0">
                    <span class="cfac-input-unit">/hr</span>
                </div>
            </div>

            <div class="cfac-subtotal cfac-subtotal-accent">
                <div class="cfac-subtotal-row">
                    <span>Your monthly time cost:</span>
                    <strong id="cfac-time-cost-monthly">$0</strong>
                </div>
                <div class="cfac-subtotal-row">
                    <span>Your annual time cost:</span>
                    <strong id="cfac-time-cost-annual">$0</strong>
                </div>
            </div>
        </div>

        <!-- Section 3: Additional Costs -->
        <div class="cfac-section">
            <h3 class="cfac-section-title">
                <span class="cfac-step-number">3</span>
                Add your related costs
            </h3>

            <div class="cfac-input-row">
                <label for="cfac_software">Monthly cost of accounting software</label>
                <div class="cfac-input-wrap">
                    <span class="cfac-input-prefix">$</span>
                    <input type="number" id="cfac_software" class="cfac-input cfac-input-dollar cfac-cost-input" min="0" step="1" placeholder="0">
                    <span class="cfac-input-unit">/mo</span>
                </div>
            </div>

            <div class="cfac-input-row">
                <label for="cfac_current_acct">Current accounting costs <span class="cfac-hint">(if using a manager, use 50% of monthly fee)</span></label>
                <div class="cfac-input-wrap">
                    <span class="cfac-input-prefix">$</span>
                    <input type="number" id="cfac_current_acct" class="cfac-input cfac-input-dollar cfac-cost-input" min="0" step="1" placeholder="0">
                    <span class="cfac-input-unit">/mo</span>
                </div>
            </div>

            <div class="cfac-input-row">
                <label for="cfac_extras">Monthly extras <span class="cfac-hint">(office supplies, checks, etc.)</span></label>
                <div class="cfac-input-wrap">
                    <span class="cfac-input-prefix">$</span>
                    <input type="number" id="cfac_extras" class="cfac-input cfac-input-dollar cfac-cost-input" min="0" step="1" placeholder="0">
                    <span class="cfac-input-unit">/mo</span>
                </div>
            </div>

            <div class="cfac-subtotal">
                <div class="cfac-subtotal-row">
                    <span>Additional costs per month:</span>
                    <strong id="cfac-additional-monthly">$0</strong>
                </div>
                <div class="cfac-subtotal-row">
                    <span>Additional costs per year:</span>
                    <strong id="cfac-additional-annual">$0</strong>
                </div>
            </div>
        </div>

        <!-- Final Result -->
        <div class="cfac-result">
            <h3 class="cfac-result-title">Your True Cost of Accounting</h3>
            <div class="cfac-result-grid">
                <div class="cfac-result-card">
                    <span class="cfac-result-label">Per Month</span>
                    <span class="cfac-result-amount" id="cfac-total-monthly">$0</span>
                </div>
                <div class="cfac-result-card">
                    <span class="cfac-result-label">Per Year</span>
                    <span class="cfac-result-amount" id="cfac-total-annual">$0</span>
                </div>
            </div>
            <p class="cfac-result-note">This includes your time cost plus all related accounting expenses.</p>
        </div>

        <!-- CTA -->
        <div class="cfac-cta">
            <h3 class="cfac-cta-title">Ready to reduce your accounting costs?</h3>
            <p>Community Financials provides expert HOA &amp; Condo accounting so you can focus on what matters most. Find out how we can save you time and money.</p>
            <a href="/request-quote/" class="cfac-cta-button">Request a Quote</a>
        </div>

    </div>
    <?php
    return ob_get_clean();
}
add_shortcode( 'cf_accounting_calculator', 'cfac_render_calculator' );
