'use client';

import { Briefcase } from 'lucide-react';

import { useLanguage } from '@/shared/language';
import { cn } from '@/shared/lib/utils';
import { Badge } from '@/shared/shadcn-ui/badge';
import { Button } from '@/shared/shadcn-ui/button';
import { Card, CardContent } from '@/shared/shadcn-ui/card';
import {
  Tabs,
  TabsContent,
  TabsList,
  TabsTrigger,
} from '@/shared/shadcn-ui/tabs';

export const VacanciesSection = () => {
  const { t } = useLanguage();

  return (
    <section id='vacancies' className='px-2 py-8 sm:py-16'>
      <div className='container mx-auto'>
        <div className='mb-12 flex flex-col items-center justify-center text-center'>
          <div className='mb-4 inline-flex items-center justify-center rounded-full bg-red-100 p-2'>
            <Briefcase className='h-6 w-6 text-red-600' />
          </div>
          <h2 className='mb-4 text-3xl font-bold tracking-tight sm:text-4xl'>
            {t('home.vacancies.title')}
          </h2>
          <p className='max-w-2xl text-gray-600'>
            {t('home.vacancies.description')}
          </p>
        </div>

        <Tabs defaultValue='all' className='mx-auto w-full max-w-3xl'>
          <TabsList className='mb-8 grid grid-cols-3'>
            <TabsTrigger value='all'>{t('home.vacancies.all')}</TabsTrigger>
            <TabsTrigger value='office'>{t('home.vacancies.office')}</TabsTrigger>
            <TabsTrigger value='stations'>{t('home.vacancies.stations')}</TabsTrigger>
          </TabsList>
          <TabsContent value='all' className='space-y-4'>
            {[
              'Оператор АЗС',
              'Менеджер по продажам',
              'Бухгалтер',
              'Специалист по логистике',
            ].map((job, index) => (
              <Vacancy
                key={index}
                jobTitle={job}
                location='Душанбе, Таджикистан'
                tags={['Полный день', 'Опыт от 1 года']}
              />
            ))}
          </TabsContent>
          <TabsContent value='office' className='space-y-4'>
            {[
              'Менеджер по продажам',
              'Бухгалтер',
              'Специалист по логистике',
            ].map((job, index) => (
              <Vacancy
                key={index}
                jobTitle={job}
                location='Душанбе, Таджикистан'
                tags={['Полный день', 'Опыт от 1 года']}
              />
            ))}
          </TabsContent>
          <TabsContent value='stations' className='space-y-4'>
            {['Оператор АЗС', 'Заправщик', 'Менеджер станции'].map(
              (job, index) => (
                <Vacancy
                  key={index}
                  jobTitle={job}
                  location='Душанбе, Таджикистан'
                  tags={['Сменный график', 'Обучение']}
                />
              ),
            )}
          </TabsContent>
        </Tabs>
      </div>
    </section>
  );
};

interface VacancyProps {
  jobTitle: string;
  location: string;
  tags: Array<string>;
}

const Vacancy = ({ jobTitle, location, tags }: VacancyProps) => {
  const { t } = useLanguage();

  return (
    <Card
      className='overflow-hidden transition-all hover:shadow-md'
      data-aos='zoom-in'
    >
      <CardContent className='p-0'>
        <div className='p-6'>
          <div className='flex flex-col items-start justify-between sm:flex-row'>
            <div>
              <h3 className='mb-2 text-lg font-bold'>{jobTitle}</h3>
              <p className='mb-4 text-sm text-gray-500'>{location}</p>
              <div className='mb-4 flex flex-wrap gap-2'>
                {tags.map((tag, index) => {
                  return (
                    <Badge
                      key={index}
                      className={cn(
                        'inline-flex items-center rounded-full bg-gray-100 px-2.5 py-0.5 text-xs font-medium',
                        `${index % 2 === 0 ? 'bg-gray-100 text-gray-800' : 'bg-red-100 text-red-800'}`,
                      )}
                    >
                      {tag}
                    </Badge>
                  );
                })}
              </div>
            </div>
            <Button variant='outline' size='sm'>
              {t('common.buttons.apply')}
            </Button>
          </div>
        </div>
      </CardContent>
    </Card>
  );
};
