import React from 'react';
import { Dumbbell, User, PlayCircle, Plus, ArrowRight } from 'lucide-react';
import { Language } from '../../types';
import { t } from '../../services/i18n';
import { useTracker } from './useTracker';

interface IdleViewProps {
    tracker: ReturnType<typeof useTracker>;
    lang: Language;
}

const IdleView: React.FC<IdleViewProps> = ({ tracker, lang }) => {
    const {
        userBodyWeight,
        setUserBodyWeight,
        handleStart,
        setIsSporadicMode,
        plans,
        showPlanPrep,
        setShowPlanPrep,
        confirmPlanStart
    } = tracker;

    return (
        <div className="flex flex-col h-full p-4 md:p-8 overflow-y-auto relative">
            <div className="flex-1 flex flex-col items-center justify-center space-y-12">
                <div className="flex flex-col items-center gap-4">
                    <div className="w-24 h-24 rounded-full bg-surface-container-high flex items-center justify-center text-primary shadow-elevation-1">
                        <Dumbbell size={40} />
                    </div>
                    <div className="text-center">
                        <h1 className="text-3xl font-normal text-on-surface">{t('ready_title', lang)}</h1>
                        <p className="text-on-surface-variant text-sm">{t('ready_subtitle', lang)}</p>
                    </div>
                </div>

                <div className="w-full max-w-sm bg-surface-container rounded-2xl p-6 flex flex-col items-center gap-4 shadow-elevation-1">
                    <label className="text-xs text-on-surface-variant font-bold tracking-wide flex items-center gap-2">
                        <User size={14} />
                        {t('my_weight', lang)}
                    </label>
                    <div className="flex items-center gap-4">
                        <input
                            type="number"
                            step="0.1"
                            className="text-5xl font-normal text-on-surface tabular-nums bg-transparent text-center w-full focus:outline-none"
                            value={userBodyWeight}
                            onChange={(e) => setUserBodyWeight(e.target.value)}
                        />
                    </div>
                    <p className="text-[10px] text-on-surface-variant">{t('change_in_profile', lang)}</p>
                </div>

                <div className="w-full max-w-xs space-y-3">
                    <button
                        onClick={() => handleStart()}
                        className="w-full h-16 rounded-full bg-primary text-on-primary font-medium text-lg shadow-elevation-2 hover:shadow-elevation-3 active:shadow-elevation-1 transition-all flex items-center justify-center gap-2"
                    >
                        <PlayCircle size={24} />
                        {t('free_workout', lang)}
                    </button>

                    <button
                        onClick={() => setIsSporadicMode(true)}
                        className="w-full h-12 rounded-full bg-surface-container-high text-on-surface font-medium text-base hover:bg-surface-container-highest transition-all flex items-center justify-center gap-2"
                    >
                        <Plus size={20} />
                        {t('quick_log', lang)}
                    </button>
                </div>

                {plans.length > 0 && (
                    <div className="w-full max-w-md mt-8">
                        <h3 className="text-sm text-on-surface-variant font-medium px-4 mb-3">{t('or_choose_plan', lang)}</h3>
                        <div className="grid grid-cols-1 gap-3">
                            {plans.map(plan => (
                                <button
                                    key={plan.id}
                                    onClick={() => handleStart(plan)}
                                    className="flex items-center justify-between p-4 bg-surface-container rounded-xl hover:bg-surface-container-high transition-colors border border-outline-variant/20"
                                >
                                    <div className="text-left">
                                        <div className="text-base font-medium text-on-surface">{plan.name}</div>
                                        <div className="text-xs text-on-surface-variant">{plan.steps.length} {t('exercises_count', lang)}</div>
                                    </div>
                                    <div className="w-10 h-10 rounded-full bg-secondary-container text-on-secondary-container flex items-center justify-center">
                                        <ArrowRight size={20} />
                                    </div>
                                </button>
                            ))}
                        </div>
                    </div>
                )}
            </div>

            {showPlanPrep && (
                <div className="absolute inset-0 bg-black/60 z-50 flex items-center justify-center p-6 backdrop-blur-sm">
                    <div className="w-full max-w-sm bg-surface-container rounded-[28px] p-6 shadow-elevation-3">
                        <h3 className="text-2xl font-normal text-on-surface mb-4">{showPlanPrep.name}</h3>
                        <div className="bg-surface-container-high p-4 rounded-xl text-on-surface-variant text-sm mb-8">
                            <div className="text-xs font-bold text-primary mb-2">{t('prep_title', lang)}</div>
                            {showPlanPrep.description || t('prep_no_instructions', lang)}
                        </div>
                        <div className="flex justify-end gap-2">
                            <button onClick={() => setShowPlanPrep(null)} className="px-6 py-2.5 rounded-full text-primary font-medium hover:bg-white/5">{t('cancel', lang)}</button>
                            <button onClick={confirmPlanStart} className="px-6 py-2.5 rounded-full bg-primary text-on-primary font-medium">{t('start', lang)}</button>
                        </div>
                    </div>
                </div>
            )}
        </div>
    );
};

export default IdleView;
