// company-filter.ts
import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';

interface Company {
  id: number;
  name: string;
  industry: string;
  location: string;
  region: string;
  distance: number;
  rating: number;
  logo: string;
  highlighted: boolean;
}

@Component({
  selector: 'app-company-filter',
  standalone: true,
  imports: [CommonModule, FormsModule],
  templateUrl: './company-filter.html',
  styleUrls: ['./company-filter.scss']
})
export class CompanyFilter {
  industries = ['全部', '科技', '金融', '医疗', '教育', '制造', '零售', '设计', '区块链'];
  regions = ['全部', '北京', '上海', '广东', '浙江', '江苏'];
  selectedIndustry = '全部';
  selectedRegion = '全部';
  radius = 10;
  
  companies: Company[] = [
    {
      id: 1,
      name: '量子科技',
      industry: '科技',
      location: '上海市徐汇区',
      region: '上海',
      distance: 2.5,
      rating: 4.8,
      logo: 'assets/company-logos/quantum.png',
      highlighted: false
    },
    {
      id: 2,
      name: '神经矩阵',
      industry: '科技',
      location: '北京市海淀区',
      region: '北京',
      distance: 5.1,
      rating: 4.6,
      logo: 'assets/company-logos/neural.png',
      highlighted: false
    },
    {
      id: 3,
      name: '数据视野',
      industry: '科技',
      location: '深圳市南山区',
      region: '广东',
      distance: 8.7,
      rating: 4.5,
      logo: 'assets/company-logos/datavision.png',
      highlighted: false
    },
    {
      id: 4,
      name: '界面未来',
      industry: '设计',
      location: '杭州市余杭区',
      region: '浙江',
      distance: 12.3,
      rating: 4.3,
      logo: 'assets/company-logos/uifuture.png',
      highlighted: false
    },
    {
      id: 5,
      name: '链芯科技',
      industry: '区块链',
      location: '上海市浦东新区',
      region: '上海',
      distance: 3.2,
      rating: 4.7,
      logo: 'assets/company-logos/chaincore.png',
      highlighted: false
    },
    {
      id: 6,
      name: '云端智能',
      industry: '科技',
      location: '广州市天河区',
      region: '广东',
      distance: 9.5,
      rating: 4.4,
      logo: 'assets/company-logos/cloudai.png',
      highlighted: false
    },
    {
      id: 7,
      name: '金陵制造',
      industry: '制造',
      location: '南京市鼓楼区',
      region: '江苏',
      distance: 15.2,
      rating: 4.2,
      logo: 'assets/company-logos/jinling.png',
      highlighted: false
    }
  ];
  
  get filteredCompanies() {
    let filtered = this.companies;
    
    // 按行业筛选
    if (this.selectedIndustry !== '全部') {
      filtered = filtered.filter(c => c.industry === this.selectedIndustry);
    }
    
    // 按地区筛选
    if (this.selectedRegion !== '全部') {
      filtered = filtered.filter(c => c.region === this.selectedRegion);
    }
    
    // 按距离筛选
    return filtered.filter(c => c.distance <= this.radius);
  }
  
  highlightCompany(company: Company) {
    this.companies.forEach(c => c.highlighted = false);
    company.highlighted = true;
  }
}