import { MetaFunction, useNavigate, useParams } from "@remix-run/react";
import { useSellerData } from "../requestHandler/use-seller-hooks";
import {
ChevronLeft,
LogOut,
LayoutDashboard,
ShoppingCart,
Truck,
PackagePlus,
TableProperties,
PenLine,
Code,
Instagram,
MessageCircle,
Users,
} from "lucide-react";
import HeaderWithSupport from "../components/HeaderWithSupport";
import { useStoreOwnership } from "../hooks/useStoreOwnership";
import { useState } from "react";
import { SunMoonToggle } from "~/components/SunMoonToggle";
import { useRootData } from "~/hooks/use-root-data";
import { PushSettingToggle } from "~/components/notifications/PushSettingToggle";
// Import the InstagramSyncDrawer component
import { InstagramSyncDrawer } from "./store.$storeId._index";
import CallDialog from "~/components/CallDialog";
interface MenuItemType {
title: string;
link?: string;
pageName: string;
hasBorder?: boolean;
ownerOnly?: boolean;
image: React.ReactNode;
}
export default function StoreSetting() {
const { storeId } = useParams();
const navigate = useNavigate();
const { data } = useSellerData(storeId);
const { theme: initialTheme } = useRootData();
// Store access guard (owner or staff). role gates owner-only menu items.
const { isLoading: isOwnershipLoading, role } = useStoreOwnership(storeId);
// State for Instagram sync drawer
const [instagramSyncDrawerOpen, setInstagramSyncDrawerOpen] = useState(false);
const [isCallModalOpen, setIsCallModalOpen] = useState(false);
// Show loading while checking ownership
if (isOwnershipLoading) {
return (
);
}
// Menu items for store management. `ownerOnly` items are hidden from staff.
const allStoreMenuItems: MenuItemType[] = [
{
title: "وارد کردن پست های اینستاگرام",
pageName: "instagram-sync",
hasBorder: true,
ownerOnly: true,
image: ,
},
{
title: "سفارشهای دریافتی",
pageName: "seller-orders",
link: `/store/${storeId}/orders`,
image: ,
},
{
title: "پیام های دریافتی",
pageName: "seller-messages",
link: `/store/${storeId}/threads`,
image: ,
},
{
title: "داشبورد مالی",
pageName: "financial-dashboard",
link: `/store/${storeId}/financial-dashboard`,
ownerOnly: true,
image: ,
},
{
title: "تعیین نحوه ارسال",
pageName: "shipping-method",
link: `/store/${storeId}/shipping-method`,
ownerOnly: true,
image: ,
},
{
title: "افزودن محصول جدید",
pageName: "add-product",
link: `/store/add/manual/${storeId}`,
image: ,
},
{
title: "لیست محصولات",
pageName: "products-list",
link: `/store/${storeId}/products`,
image: ,
},
{
title: "مدیریت اعضای تیم",
pageName: "team",
link: `/store/${storeId}/team`,
ownerOnly: true,
image: ,
},
{
title: "ویرایش اطلاعات فروشگاه",
pageName: "edit-store",
link: `/store/${storeId}/edit`,
ownerOnly: true,
image: ,
},
{
title: "خروج",
pageName: "logout",
link: `/store/${storeId}/logout`,
hasBorder: true,
image: ,
},
];
const storeMenuItems = allStoreMenuItems.filter(
(item) => !item.ownerOnly || role === "owner"
);
const handleBack = () => {
navigate(`/store/${storeId}`);
};
const handleItemClick = (item: MenuItemType) => {
// Special handling for "instagram-sync" item
if (item.pageName === "instagram-sync") {
// Open Instagram sync drawer instead of navigating
setInstagramSyncDrawerOpen(true);
return;
}
// Special handling for "logout" item
if (item.pageName === "logout") {
// Handle logout logic
navigate("/");
return;
}
// Default rendering for other items with Link if they have a link
if (item.link) {
navigate(item.link);
return;
}
};
return (
{/* Header */}
تنظیمات فروشگاه
{/* Status + Theme cards */}
{/* Store Status */}
{/* Theme Toggle */}
{initialTheme === "dark" ? "حالت تاریک" : "حالت روشن"}
تغییر حالت نمایش به تاریک یا روشن
{/* Push notifications */}
{/* Menu Items */}
{storeMenuItems.map((item, index) => {
const isLogout = item.pageName === "logout";
return (
handleItemClick(item)}
role="button"
tabIndex={0}
onKeyDown={(e) => {
if (e.key === "Enter" || e.key === " ") {
handleItemClick(item);
}
}}
>
{item.image}
{item.title}
);
})}
{/* Instagram Sync Drawer */}
{
window.location.href = `tel:${import.meta.env.VITE_SUPPORT_PHONE}`;
}}
/>
);
}
export const meta: MetaFunction = () => {
return [
{ title: "تنظیمات فروشگاه - ویترون" },
{
name: "description",
content:
"مدیریت و مشاهده تمام تنظیمات فروشگاه در فروشگاه شما. فیلتر بر اساس وضعیت و جستجو در تنظیمات فروشگاه.",
},
{
name: "keywords",
content:
"تنظیمات فروشگاه، مدیریت تنظیمات فروشگاه، فروشگاه، مشتری، ویترون",
},
{ name: "robots", content: "noindex, follow" },
{ property: "og:title", content: "تنظیمات فروشگاه - ویترون" },
{
property: "og:description",
content:
"مدیریت و مشاهده تمام تنظیمات فروشگاه در فروشگاه شما. فیلتر بر اساس وضعیت و جستجو در تنظیمات فروشگاه.",
},
{ property: "og:type", content: "website" },
{ name: "twitter:card", content: "summary" },
{ name: "twitter:title", content: "تنظیمات فروشگاه - ویترون" },
{
name: "twitter:description",
content:
"مدیریت و مشاهده تمام تنظیمات فروشگاه در فروشگاه شما. فیلتر بر اساس وضعیت و جستجو در تنظیمات فروشگاه.",
},
];
};