#!/usr/bin/env python3
"""Inspect Excel file structure"""
import pandas as pd
import sys

file_path = '../KPI Manager Information Technology.xlsx'

print("=" * 70)
print(f"Inspecting: {file_path}")
print("=" * 70)

try:
    xls = pd.ExcelFile(file_path)
    print(f"\nTotal sheets: {len(xls.sheet_names)}")
    print(f"Sheet names: {xls.sheet_names}")
    
    # Inspect KPI sheet
    print("\n" + "=" * 70)
    print("KPI Sheet (first 20 rows):")
    print("=" * 70)
    df_kpi = pd.read_excel(xls, sheet_name='KPI', header=None)
    print(f"Shape: {df_kpi.shape}")
    print("\nFirst 20 rows:")
    pd.set_option('display.max_columns', None)
    pd.set_option('display.width', None)
    pd.set_option('display.max_colwidth', 50)
    print(df_kpi.head(20))
    
    # Inspect Achievement sheet
    if 'Achievement' in xls.sheet_names:
        print("\n" + "=" * 70)
        print("Achievement Sheet:")
        print("=" * 70)
        df_ach = pd.read_excel(xls, sheet_name='Achievement')
        print(f"Shape: {df_ach.shape}")
        print(f"Columns: {df_ach.columns.tolist()}")
        print("\nFirst 10 rows:")
        print(df_ach.head(10))
    
    # Inspect one detail sheet
    detail_sheets = [s for s in xls.sheet_names if s not in ['KPI', 'Achievement']]
    if detail_sheets:
        sample_sheet = detail_sheets[0]
        print("\n" + "=" * 70)
        print(f"Sample Detail Sheet: {sample_sheet}")
        print("=" * 70)
        df_detail = pd.read_excel(xls, sheet_name=sample_sheet, header=None)
        print(f"Shape: {df_detail.shape}")
        print("\nFirst 15 rows:")
        print(df_detail.head(15))
        
except Exception as e:
    print(f"Error: {e}")
    import traceback
    traceback.print_exc()
