# -*- coding: utf-8 -*-
"""
필터 칩
- 클릭하면 removed(key) 발생 (선택 개념 없음)
"""

from __future__ import annotations

from typing import Optional

from PySide6.QtCore import Signal

from ui.components.chips.chip_base_button import ChipBaseButton, ChipTheme


class FilterChipButton(ChipBaseButton):
    """
    필터 칩 버튼
    - 클릭하면 removed(filter_key) 신호 발생
    - hover 시 "삭제 가능" 시각적 강조
    """
    
    removed = Signal(str)  # filter_key

    def __init__(
        self,
        text: str,
        filter_key: str,
        filter_type: str = "",
        color: Optional[str] = None,
        theme: ChipTheme = ChipTheme(),
        parent=None,
    ):
        bg = color or self._default_color(filter_type)
        super().__init__(
            text=text,
            key=filter_key,
            bg=bg,
            theme=theme,
            checkable=False,
            parent=parent,
        )
        self.setToolTip("클릭하여 제거")
        self.clicked_key.connect(self._emit_removed)

    def _emit_removed(self, key: str):
        """제거 신호 발생"""
        self.removed.emit(key)

    @staticmethod
    def _default_color(filter_type: str) -> str:
        """필터 타입별 기본 색상"""
        color_map = {
            "date": "#7c4dff",
            "team": "#2979ff",
            "status": "#00bfa5",
            "search": "#ff4081",
            "device": "#ff9800",
            "train": "#607d8b",
        }
        return color_map.get(filter_type, "#64748b")





