2024-06-02 23:41:46 +03:00
|
|
|
'use client';
|
|
|
|
|
2024-10-29 12:45:03 +03:00
|
|
|
import clsx from 'clsx';
|
2024-06-02 23:41:46 +03:00
|
|
|
|
2025-01-28 23:23:42 +03:00
|
|
|
import { LocationIcon } from '@/components/DomainIcons';
|
|
|
|
import { CProps } from '@/components/props';
|
2024-06-02 23:41:46 +03:00
|
|
|
import Dropdown from '@/components/ui/Dropdown';
|
2025-01-28 23:23:42 +03:00
|
|
|
import DropdownButton from '@/components/ui/DropdownButton';
|
2024-06-02 23:41:46 +03:00
|
|
|
import SelectorButton from '@/components/ui/SelectorButton';
|
|
|
|
import useDropdown from '@/hooks/useDropdown';
|
|
|
|
import { LocationHead } from '@/models/library';
|
|
|
|
import { prefixes } from '@/utils/constants';
|
|
|
|
import { describeLocationHead, labelLocationHead } from '@/utils/labels';
|
|
|
|
|
2024-10-29 12:45:03 +03:00
|
|
|
interface SelectLocationHeadProps extends CProps.Styling {
|
2024-06-02 23:41:46 +03:00
|
|
|
value: LocationHead;
|
2024-06-21 19:27:36 +03:00
|
|
|
onChange: (newValue: LocationHead) => void;
|
2024-06-02 23:41:46 +03:00
|
|
|
excluded?: LocationHead[];
|
|
|
|
}
|
|
|
|
|
2024-10-29 12:45:03 +03:00
|
|
|
function SelectLocationHead({ value, excluded = [], onChange, className, ...restProps }: SelectLocationHeadProps) {
|
2024-06-02 23:41:46 +03:00
|
|
|
const menu = useDropdown();
|
|
|
|
|
2025-02-05 01:27:52 +03:00
|
|
|
function handleChange(newValue: LocationHead) {
|
|
|
|
menu.hide();
|
|
|
|
onChange(newValue);
|
|
|
|
}
|
2024-06-02 23:41:46 +03:00
|
|
|
|
|
|
|
return (
|
2024-10-29 12:45:03 +03:00
|
|
|
<div ref={menu.ref} className={clsx('h-full text-right', className)} {...restProps}>
|
2024-06-02 23:41:46 +03:00
|
|
|
<SelectorButton
|
|
|
|
transparent
|
|
|
|
tabIndex={-1}
|
|
|
|
title={describeLocationHead(value)}
|
|
|
|
hideTitle={menu.isOpen}
|
|
|
|
className='h-full'
|
2024-06-04 11:19:21 +03:00
|
|
|
icon={<LocationIcon value={value} size='1rem' />}
|
2024-06-02 23:41:46 +03:00
|
|
|
text={labelLocationHead(value)}
|
|
|
|
onClick={menu.toggle}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Dropdown isOpen={menu.isOpen} className='z-modalTooltip'>
|
|
|
|
{Object.values(LocationHead)
|
|
|
|
.filter(head => !excluded.includes(head))
|
|
|
|
.map((head, index) => {
|
|
|
|
return (
|
|
|
|
<DropdownButton
|
|
|
|
className='w-[10rem]'
|
|
|
|
key={`${prefixes.location_head_list}${index}`}
|
|
|
|
onClick={() => handleChange(head)}
|
|
|
|
title={describeLocationHead(head)}
|
|
|
|
>
|
|
|
|
<div className='inline-flex items-center gap-3'>
|
2024-06-04 11:19:21 +03:00
|
|
|
<LocationIcon value={head} size='1rem' />
|
2024-06-02 23:41:46 +03:00
|
|
|
{labelLocationHead(head)}
|
|
|
|
</div>
|
|
|
|
</DropdownButton>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</Dropdown>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SelectLocationHead;
|