import { Injectable } from '@angular/core';
import { SVGIcon } from '@progress/kendo-angular-icons';
import { EscrowStatus, CbAssigneeRole } from '../models/enums.model';
import { Subject } from 'rxjs';

@Injectable({
    providedIn: 'root'
})
export class UiUtilsService {
    public setPageTitleSubject = new Subject<string>();
    public setPageTitle$ = this.setPageTitleSubject.asObservable();
    // Icon properties - these should be injected or provided by a parent component
    // For now, we'll make them optional and let the calling component provide them
    checkCircleIcon?: SVGIcon;
    clockIcon?: SVGIcon;
    alertCircleIcon?: SVGIcon;
    userIcon?: SVGIcon;

    constructor() { }

    /**
     * Get CSS class for church status
     */
    getStatusClass(status: EscrowStatus): string {
        switch (status) {
            case EscrowStatus.Open:
                return 'status-active';
            case EscrowStatus.Closed:
                return 'status-completed';
            case EscrowStatus.Cancelled:
                return 'status-cancelled';
            default:
                return '';
        }
    }

    /**
     * Get display label for church status
     */
    getEscrowStatusLabel(status: EscrowStatus): string {
        switch (status) {
            case EscrowStatus.Open:
                return 'Open';
            case EscrowStatus.Closed:
                return 'Closed';
            case EscrowStatus.Cancelled:
                return 'Cancelled';
            default:
                return '';
        }
    }

    /**
     * Get CSS class for priority level
     */
    getPriorityClass(priority: string): string {
        switch (priority) {
            case 'high':
                return 'priority-high';
            case 'medium':
                return 'priority-medium';
            case 'low':
                return 'priority-low';
            default:
                return '';
        }
    }

    /**
     * Get icon for church status
     */
    getStatusIcon(status: EscrowStatus): SVGIcon | undefined {
        switch (status) {
            case EscrowStatus.Open:
                return this.checkCircleIcon;
            case EscrowStatus.Closed:
                return this.checkCircleIcon;
            case EscrowStatus.Cancelled:
                return this.alertCircleIcon;
            default:
                return this.clockIcon;
        }
    }

    /**
     * Get CSS class for assignee role
     */
    getRoleClass(role: CbAssigneeRole): string {
        switch (role) {
            case CbAssigneeRole.Buyer:
                return 'role-buyer';
            case CbAssigneeRole.Seller:
                return 'role-seller';
            case CbAssigneeRole.BuyerRealEstateAgent:
            case CbAssigneeRole.SellerRealEstateAgent:
                return 'role-agent';
            case CbAssigneeRole.EscrowOfficer:
            case CbAssigneeRole.EscrowAssignee:
                return 'role-church';
            case CbAssigneeRole.LoanBroker:
            case CbAssigneeRole.Lender:
                return 'role-lender';
            case CbAssigneeRole.SellerTransactionCoordinator:
            case CbAssigneeRole.BuyerTransactionCoordinator:
                return 'role-coordinator';
            case CbAssigneeRole.None:
                return 'role-default';
            default:
                return 'role-default';
        }
    }

    /**
     * Get icon for assignee role
     */
    getRoleIcon(role: CbAssigneeRole): SVGIcon | undefined {
        switch (role) {
            case CbAssigneeRole.Buyer:
            case CbAssigneeRole.Seller:
            case CbAssigneeRole.BuyerRealEstateAgent:
            case CbAssigneeRole.SellerRealEstateAgent:
            case CbAssigneeRole.EscrowOfficer:
            case CbAssigneeRole.EscrowAssignee:
            case CbAssigneeRole.LoanBroker:
            case CbAssigneeRole.Lender:
            case CbAssigneeRole.SellerTransactionCoordinator:
            case CbAssigneeRole.BuyerTransactionCoordinator:
                return this.userIcon;
            case CbAssigneeRole.None:
                return this.userIcon;
            default:
                return this.userIcon;
        }
    }

    /**
     * Get display label for assignee role
     */
    getRoleLabel(role: CbAssigneeRole): string {
        switch (role) {
            case CbAssigneeRole.Buyer:
                return 'Buyer';
            case CbAssigneeRole.Seller:
                return 'Seller';
            case CbAssigneeRole.BuyerRealEstateAgent:
                return 'Buyer Agent';
            case CbAssigneeRole.SellerRealEstateAgent:
                return 'Seller Agent';
            case CbAssigneeRole.EscrowOfficer:
                return 'Escrow Officer';
            case CbAssigneeRole.EscrowAssignee:
                return 'Escrow Assignee';
            case CbAssigneeRole.LoanBroker:
                return 'Loan Broker';
            case CbAssigneeRole.Lender:
                return 'Lender';
            case CbAssigneeRole.SellerTransactionCoordinator:
                return 'Seller Coordinator';
            case CbAssigneeRole.BuyerTransactionCoordinator:
                return 'Buyer Coordinator';
            case CbAssigneeRole.None:
                return 'None';
            default:
                return 'Unknown';
        }
    }

    /**
     * Set icons for the service (should be called by components that use this service)
     */
    setIcons(icons: {
        checkCircleIcon?: SVGIcon;
        clockIcon?: SVGIcon;
        alertCircleIcon?: SVGIcon;
        userIcon?: SVGIcon;
    }): void {
        this.checkCircleIcon = icons.checkCircleIcon;
        this.clockIcon = icons.clockIcon;
        this.alertCircleIcon = icons.alertCircleIcon;
        this.userIcon = icons.userIcon;
    }
}
