import { ChevronDown } from "lucide-react";
import { useTranslation } from "react-i18next";
import { useLayout, type LayoutId } from "@/store/layoutStore";

const OPTIONS: Array<{ id: LayoutId; labelKey: string }> = [
  { id: "sidebar", labelKey: "layout.sidebar" },
  { id: "topnav", labelKey: "layout.topnav" },
  { id: "compact", labelKey: "layout.compact" },
  { id: "wide", labelKey: "layout.wide" },
];

export function LayoutSwitcher() {
  const { t } = useTranslation();
  const { layout, setLayout } = useLayout();

  return (
    <div className="relative">
      <label htmlFor="layout-select" className="sr-only">
        {t("layout.label")}
      </label>
      <select
        id="layout-select"
        value={layout}
        onChange={(e) => setLayout(e.target.value as LayoutId)}
        className="select !w-auto !py-2 !pr-9 !text-sm"
        aria-label={t("layout.label")}
      >
        {OPTIONS.map(({ id, labelKey }) => (
          <option key={id} value={id}>
            {t(labelKey)}
          </option>
        ))}
      </select>
      <ChevronDown
        className="pointer-events-none absolute right-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-slate-400"
        aria-hidden="true"
      />
    </div>
  );
}
