<?php

defined('BASEPATH') or exit('No direct script access allowed');
/*
Module Name: Project Costing
Description: INCEIF Project Costing
Version: 1.0.0
Requires at least: 3.4.*
*/
define('PROJECT_COSTING_MODULE_NAME', 'project_costing');

hooks()->add_action('admin_init', 'project_costing_module_init_menu_items');
hooks()->add_action('admin_init', 'project_costing_permissions');
hooks()->add_action('app_admin_head', 'project_costing_add_head_components');

register_activation_hook(PROJECT_COSTING_MODULE_NAME, 'project_costing_module_activation_hook');

function project_costing_module_activation_hook()
{
    $CI = &get_instance();
    require_once(__DIR__ . '/install.php');
}

function project_costing_permissions()
{
    $capabilities = [];

    $capabilities['capabilities'] = [
        'view'   => _l('permission_view'),
        'create' => _l('permission_create'),
        'edit'   => _l('permission_edit'),
        'delete' => _l('permission_delete'),
    ];

    register_staff_capabilities('project_costing', $capabilities, _l('project_costing'));
}

function project_costing_module_init_menu_items()
{
    $CI = &get_instance();

    if (has_permission('project_costing', '', 'view')) {
        $CI->app_menu->add_sidebar_menu_item('project-costing', [
            'slug'     => 'project-costing',
            'name'     => _l('project_costing'),
            'icon'     => 'fa fa-calculator',
            'position' => 35,
        ]);

        $CI->app_menu->add_sidebar_children_item('project-costing', [
            'slug'     => 'project-costing-dashboard',
            'name'     => _l('project_costing_dashboard'),
            'href'     => admin_url('project_costing/project_costing_admin'),
            'position' => 1,
        ]);
if (is_admin()){
        $CI->app_menu->add_sidebar_children_item('project-costing', [
            'slug'     => 'project-costing-client-categories',
            'name'     => _l('project_costing_client_categories'),
            'href'     => admin_url('project_costing/project_costing_admin/client_categories'),
            'position' => 2,
        ]);

        $CI->app_menu->add_sidebar_children_item('project-costing', [
            'slug'     => 'project-costing-engagement-types',
            'name'     => _l('project_costing_engagement_types'),
            'href'     => admin_url('project_costing/project_costing_admin/engagement_types'),
            'position' => 3,
        ]);

        $CI->app_menu->add_sidebar_children_item('project-costing', [
            'slug'     => 'project-costing-approval-settings',
            'name'     => _l('project_costing_approval_settings'),
            'href'     => admin_url('project_costing/project_costing_admin/approval_settings'),
            'position' => 4,
        ]);
        }
         // User
        $CI->app_menu->add_sidebar_children_item('project-costing', [
            'slug'     => 'project-costing-my-submissions',
            'name'     => 'My Submissions',
            'href'     => admin_url('project_costing/project_costing'),
            'position' => 5,
        ]);

        $CI->app_menu->add_sidebar_children_item('project-costing', [
            'slug'     => 'project-costing-new',
            'name'     => 'New Project',
            'href'     => admin_url('project_costing/project_costing/create'),
            'position' => 6,
        ]);
        $CI->app_menu->add_sidebar_children_item('project-costing', [
    'slug'     => 'project-costing-finance-review',
    'name'     => 'Finance Review',
    'href'     => admin_url('project_costing/project_costing/finance_list'),
    'position' => 7,
]);

$CI->app_menu->add_sidebar_children_item('project-costing', [
    'slug'     => 'project-costing-hod-review',
    'name'     => 'HOD Review',
    'href'     => admin_url('project_costing/project_costing/hod_list'),
    'position' => 8,
]);
    }
}

function project_costing_add_head_components()
{
    echo '<style>
        .pc-card-stat{
            border:1px solid #e5e5e5;
            border-radius:10px;
            padding:20px;
            background:#fff;
            margin-bottom:20px;
            min-height:120px;
        }
        .pc-card-stat h3{
            margin:0;
            font-size:28px;
            font-weight:700;
        }
        .pc-card-stat p{
            margin:8px 0 0;
            color:#777;
        }
        .pc-box{
            border:1px solid #e5e5e5;
            background:#fafafa;
            border-radius:10px;
            padding:15px;
            margin-bottom:20px;
        }
        .pc-box h5{
            margin-top:0;
            margin-bottom:15px;
            font-weight:600;
        }
        .pc-section-box{
            border:1px solid #dcdcdc;
            background:#fff;
            border-radius:10px;
            padding:15px;
            margin-bottom:20px;
        }
        .pc-section-title{
            font-size:16px;
            font-weight:700;
            margin-bottom:15px;
        }
        .pc-summary-box{
            background:#f7f7f7;
            border:1px solid #e5e5e5;
            padding:15px;
            border-radius:10px;
        }
        .approval-step{
            min-width:220px;
            min-height:120px;
            border-radius:12px;
            padding:15px;
            text-align:center;
            font-weight:600;
            border:1px solid #ddd;
            background:#fafafa;
        }
        .approval-step-approved{
            background:#dff0d8;
            border-color:#b2dba1;
        }
        .approval-step-rejected{
            background:#f2dede;
            border-color:#e0b1b8;
        }
        .approval-step-ongoing{
            background:#fcf8e3;
            border-color:#faebcc;
        }
        .approval-step-idle{
            background:#f5f5f5;
            border-color:#ddd;
        }
        .approval-step-start{
            background:#d9edf7;
            border-color:#bcdff1;
        }
        .approval-step-header{
            font-size:15px;
            font-weight:700;
            margin-bottom:10px;
        }
        .approver-label{
            font-size:13px;
            font-weight:500;
        }
        .muted{
            color:#777;
        }
    </style>';
    echo '<style>
    .pc-form-header{
        margin-bottom: 10px;
    }
    .pc-form-box{
        background: #fafbfc;
        border: 1px solid #e6eaef;
        border-radius: 12px;
        padding: 20px 20px 5px;
    }
    .pc-percentage-box{
        background: linear-gradient(135deg, #f8fbff 0%, #f3f7fb 100%);
        border: 1px solid #dfe7f1;
        border-radius: 12px;
        padding: 20px 20px 5px;
    }
    .pc-form-box .form-group,
    .pc-percentage-box .form-group{
        margin-bottom: 18px;
    }
    .pc-form-box label,
    .pc-percentage-box label{
        font-weight: 600;
        color: #2f3b52;
        margin-bottom: 6px;
    }
    .pc-form-box .bootstrap-select > .dropdown-toggle,
    .pc-percentage-box input.form-control{
        border-radius: 8px;
        min-height: 40px;
    }
    .pc-percentage-box input.form-control[readonly]{
        background: #fff;
        font-weight: 600;
        color: #1f3c5a;
    }
    .pc-step-label{
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    color: #24364b;
    margin-bottom: 8px;
}

.pc-step-badge{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: linear-gradient(135deg, #34c759 0%, #1f9d45 100%);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    box-shadow: 0 3px 8px rgba(31, 157, 69, 0.28);
    border: 2px solid #eaf8ee;
}
</style>';
echo '<style>
    .pc-summary-table thead th{
        background:#f5f7fa;
        font-weight:700;
        color:#2f3b52;
    }
    .pc-summary-table tbody tr.info td{
        background:#eef6ff !important;
    }

    .pc-summary-table thead th{
        background:#f4f6f9;
        color:#2f3b52;
        font-weight:700;
    }
    .pc-summary-table tbody tr td{
        vertical-align:middle;
    }
    .pc-summary-table tbody tr.info td{
        background:#eef6ff !important;
        font-weight:700;
    }
    .pc-summary-table tbody tr.success td{
        background:#edf8f0 !important;
        font-weight:700;
    }
</style>';
}
// Load module language files
register_language_files(PROJECT_COSTING_MODULE_NAME, ['project_costing']);