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11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
import React, { useState } from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import { 
  Calendar as CalendarIcon,
  ChevronLeft,
  ChevronRight,
  Plus,
  Clock,
  Layers,
  Image,
  FileText,
  Video,
  Filter,
  Settings,
  Sparkles,
  Check,
  X,
  GripVertical
} from 'lucide-react';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import { Badge } from '@/components/ui/badge';
import { Calendar } from '@/components/ui/calendar';
import { Checkbox } from '@/components/ui/checkbox';
import { Label } from '@/components/ui/label';
import { Slider } from '@/components/ui/slider';
import {
  Select,
  SelectContent,
  SelectItem,
  SelectTrigger,
  SelectValue,
} from '@/components/ui/select';
import {
  Dialog,
  DialogContent,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from '@/components/ui/dialog';
import {
  Popover,
  PopoverContent,
  PopoverTrigger,
} from '@/components/ui/popover';
import { format, addDays, startOfWeek, endOfWeek, eachDayOfInterval, isSameDay, isToday } from 'date-fns';
import { Link } from 'react-router-dom';
import { createPageUrl } from '@/utils';

const products = [
  { id: 'ocr', name: 'Document Parsing (OCR)', shortName: 'OCR', color: 'blue' },
  { id: 'p2p', name: 'Purchase To Pay', shortName: 'P2P', color: 'emerald', subCategories: ['Budget Approval', 'Purchase Request', 'Accounts Payable'] },
  { id: 'o2c', name: 'Order to Cash', shortName: 'O2C', color: 'violet', subCategories: ['Quotation', 'Sales Order', 'PickSlip Delivery', 'Accounts Receivable'] },
];

const postTypes = [
  { id: 'carousel', name: 'Carousel', icon: Layers, description: 'Multi-slide visual story' },
  { id: 'cover_content', name: 'Cover Image + Content', icon: Image, description: 'Featured image with text' },
  { id: 'content_only', name: 'Content Only', icon: FileText, description: 'Text-based post' },
  { id: 'webinar', name: 'Webinar Invite', icon: Video, description: 'Event promotion' },
];

const scheduledPosts = [
  { id: 1, title: 'OCR Automation Benefits', type: 'carousel', product: 'ocr', time: '10:00 AM', date: new Date(), status: 'scheduled' },
  { id: 2, title: 'P2P Efficiency Guide', type: 'cover_content', product: 'p2p', time: '2:00 PM', date: new Date(), status: 'draft' },
  { id: 3, title: 'O2C Webinar', type: 'webinar', product: 'o2c', time: '11:00 AM', date: addDays(new Date(), 1), status: 'scheduled' },
  { id: 4, title: 'Invoice Processing Tips', type: 'content_only', product: 'ocr', time: '3:00 PM', date: addDays(new Date(), 1), status: 'scheduled' },
  { id: 5, title: 'Budget Approval Flow', type: 'carousel', product: 'p2p', time: '9:00 AM', date: addDays(new Date(), 2), status: 'scheduled' },
  { id: 6, title: 'Sales Order Demo', type: 'cover_content', product: 'o2c', time: '1:00 PM', date: addDays(new Date(), 3), status: 'draft' },
];

export default function Scheduler() {
  const [selectedDate, setSelectedDate] = useState(new Date());
  const [currentWeekStart, setCurrentWeekStart] = useState(startOfWeek(new Date(), { weekStartsOn: 1 }));
  const [campaignDialogOpen, setCampaignDialogOpen] = useState(false);
  const [selectedProducts, setSelectedProducts] = useState(['ocr', 'p2p', 'o2c']);
  const [selectedPostTypes, setSelectedPostTypes] = useState(['carousel', 'cover_content']);
  const [dateRange, setDateRange] = useState({ from: new Date(), to: addDays(new Date(), 30) });
  const [postsPerWeek, setPostsPerWeek] = useState([5]);

  const weekDays = eachDayOfInterval({
    start: currentWeekStart,
    end: endOfWeek(currentWeekStart, { weekStartsOn: 1 })
  });

  const navigateWeek = (direction) => {
    setCurrentWeekStart(prev => addDays(prev, direction === 'next' ? 7 : -7));
  };

  const getPostsForDate = (date) => {
    return scheduledPosts.filter(post => isSameDay(post.date, date));
  };

  const getProductColor = (productId) => {
    const product = products.find(p => p.id === productId);
    return product?.color || 'slate';
  };

  const getPostTypeIcon = (typeId) => {
    const type = postTypes.find(t => t.id === typeId);
    return type?.icon || FileText;
  };

  const toggleProduct = (productId) => {
    setSelectedProducts(prev => 
      prev.includes(productId)
        ? prev.filter(id => id !== productId)
        : [...prev, productId]
    );
  };

  const togglePostType = (typeId) => {
    setSelectedPostTypes(prev => 
      prev.includes(typeId)
        ? prev.filter(id => id !== typeId)
        : [...prev, typeId]
    );
  };

  return (
    <div className="min-h-screen bg-gradient-to-br from-slate-50 via-white to-blue-50/30">
      <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
        {/* Header */}
        <motion.div 
          initial={{ opacity: 0, y: -20 }}
          animate={{ opacity: 1, y: 0 }}
          className="mb-8"
        >
          <div className="flex flex-col md:flex-row md:items-center md:justify-between gap-4">
            <div>
              <h1 className="text-3xl font-bold text-slate-900 tracking-tight">
                Content Scheduler
              </h1>
              <p className="text-slate-500 mt-1">
                Plan and schedule your LinkedIn content calendar
              </p>
            </div>
            <div className="flex gap-3">
              <Dialog open={campaignDialogOpen} onOpenChange={setCampaignDialogOpen}>
                <DialogTrigger asChild>
                  <Button variant="outline" className="gap-2 border-slate-200">
                    <Settings className="w-4 h-4" />
                    Campaign Settings
                  </Button>
                </DialogTrigger>
                <DialogContent className="sm:max-w-2xl max-h-[90vh] overflow-y-auto">
                  <DialogHeader>
                    <DialogTitle className="flex items-center gap-2">
                      <Sparkles className="w-5 h-5 text-amber-500" />
                      Configure Campaign
                    </DialogTitle>
                  </DialogHeader>
                  <div className="space-y-6 pt-4">
                    {/* Date Range */}
                    <div className="space-y-3">
                      <Label className="text-sm font-semibold">Campaign Date Range</Label>
                      <div className="grid grid-cols-2 gap-4">
                        <div>
                          <Label className="text-xs text-slate-500">Start Date</Label>
                          <Popover>
                            <PopoverTrigger asChild>
                              <Button variant="outline" className="w-full justify-start mt-1.5">
                                <CalendarIcon className="w-4 h-4 mr-2" />
                                {format(dateRange.from, 'MMM d, yyyy')}
                              </Button>
                            </PopoverTrigger>
                            <PopoverContent className="w-auto p-0" align="start">
                              <Calendar
                                mode="single"
                                selected={dateRange.from}
                                onSelect={(date) => setDateRange(prev => ({ ...prev, from: date }))}
                              />
                            </PopoverContent>
                          </Popover>
                        </div>
                        <div>
                          <Label className="text-xs text-slate-500">End Date</Label>
                          <Popover>
                            <PopoverTrigger asChild>
                              <Button variant="outline" className="w-full justify-start mt-1.5">
                                <CalendarIcon className="w-4 h-4 mr-2" />
                                {format(dateRange.to, 'MMM d, yyyy')}
                              </Button>
                            </PopoverTrigger>
                            <PopoverContent className="w-auto p-0" align="start">
                              <Calendar
                                mode="single"
                                selected={dateRange.to}
                                onSelect={(date) => setDateRange(prev => ({ ...prev, to: date }))}
                              />
                            </PopoverContent>
                          </Popover>
                        </div>
                      </div>
                    </div>

                    {/* Products to Focus */}
                    <div className="space-y-3">
                      <Label className="text-sm font-semibold">Products to Focus</Label>
                      <div className="grid gap-3">
                        {products.map(product => (
                          <div key={product.id} className="space-y-2">
                            <div 
                              onClick={() => toggleProduct(product.id)}
                              className={`flex items-center gap-3 p-3 rounded-xl border cursor-pointer transition-all ${
                                selectedProducts.includes(product.id)
                                  ? `border-${product.color}-300 bg-${product.color}-50`
                                  : 'border-slate-200 hover:border-slate-300'
                              }`}
                            >
                              <div className={`w-8 h-8 rounded-lg flex items-center justify-center ${
                                selectedProducts.includes(product.id)
                                  ? `bg-${product.color}-500 text-white`
                                  : 'bg-slate-100 text-slate-400'
                              }`}>
                                {selectedProducts.includes(product.id) ? (
                                  <Check className="w-4 h-4" />
                                ) : (
                                  <Plus className="w-4 h-4" />
                                )}
                              </div>
                              <div className="flex-1">
                                <p className="font-medium text-slate-900">{product.name}</p>
                                {product.subCategories && (
                                  <p className="text-xs text-slate-500 mt-0.5">
                                    {product.subCategories.join(', ')}
                                  </p>
                                )}
                              </div>
                            </div>
                          </div>
                        ))}
                      </div>
                    </div>

                    {/* Post Types Mix */}
                    <div className="space-y-3">
                      <Label className="text-sm font-semibold">Post Types Mix</Label>
                      <div className="grid grid-cols-2 gap-3">
                        {postTypes.map(type => (
                          <div
                            key={type.id}
                            onClick={() => togglePostType(type.id)}
                            className={`flex items-center gap-3 p-3 rounded-xl border cursor-pointer transition-all ${
                              selectedPostTypes.includes(type.id)
                                ? 'border-blue-300 bg-blue-50'
                                : 'border-slate-200 hover:border-slate-300'
                            }`}
                          >
                            <div className={`w-10 h-10 rounded-lg flex items-center justify-center ${
                              selectedPostTypes.includes(type.id)
                                ? 'bg-blue-500 text-white'
                                : 'bg-slate-100 text-slate-400'
                            }`}>
                              <type.icon className="w-5 h-5" />
                            </div>
                            <div>
                              <p className="font-medium text-sm text-slate-900">{type.name}</p>
                              <p className="text-xs text-slate-500">{type.description}</p>
                            </div>
                          </div>
                        ))}
                      </div>
                    </div>

                    {/* Posting Frequency */}
                    <div className="space-y-3">
                      <div className="flex items-center justify-between">
                        <Label className="text-sm font-semibold">Posts per Week</Label>
                        <span className="text-lg font-bold text-blue-600">{postsPerWeek[0]}</span>
                      </div>
                      <Slider
                        value={postsPerWeek}
                        onValueChange={setPostsPerWeek}
                        min={1}
                        max={14}
                        step={1}
                        className="py-4"
                      />
                      <div className="flex justify-between text-xs text-slate-500">
                        <span>1 post</span>
                        <span>14 posts</span>
                      </div>
                    </div>

                    <div className="flex justify-end gap-2 pt-4 border-t">
                      <Button variant="outline" onClick={() => setCampaignDialogOpen(false)}>
                        Cancel
                      </Button>
                      <Button className="bg-gradient-to-r from-blue-600 to-indigo-600 gap-2">
                        <Sparkles className="w-4 h-4" />
                        Generate Schedule
                      </Button>
                    </div>
                  </div>
                </DialogContent>
              </Dialog>
              
              <Link to={createPageUrl('PostEditor')}>
                <Button className="gap-2 bg-gradient-to-r from-blue-600 to-indigo-600 hover:from-blue-700 hover:to-indigo-700 shadow-lg shadow-blue-500/25">
                  <Plus className="w-4 h-4" />
                  Create Post
                </Button>
              </Link>
            </div>
          </div>
        </motion.div>

        <div className="grid lg:grid-cols-4 gap-6">
          {/* Calendar Sidebar */}
          <motion.div
            initial={{ opacity: 0, x: -20 }}
            animate={{ opacity: 1, x: 0 }}
            className="lg:col-span-1 space-y-6"
          >
            <Card className="border-0 shadow-lg shadow-slate-200/50">
              <CardContent className="p-4">
                <Calendar
                  mode="single"
                  selected={selectedDate}
                  onSelect={setSelectedDate}
                  className="rounded-md"
                />
              </CardContent>
            </Card>

            {/* Quick Stats */}
            <Card className="border-0 shadow-lg shadow-slate-200/50">
              <CardHeader className="pb-3">
                <CardTitle className="text-sm font-semibold text-slate-600">This Week</CardTitle>
              </CardHeader>
              <CardContent className="space-y-3">
                <div className="flex items-center justify-between">
                  <span className="text-sm text-slate-600">Scheduled</span>
                  <Badge className="bg-blue-100 text-blue-700 border-0">12 posts</Badge>
                </div>
                <div className="flex items-center justify-between">
                  <span className="text-sm text-slate-600">Drafts</span>
                  <Badge className="bg-amber-100 text-amber-700 border-0">4 posts</Badge>
                </div>
                <div className="flex items-center justify-between">
                  <span className="text-sm text-slate-600">Published</span>
                  <Badge className="bg-emerald-100 text-emerald-700 border-0">8 posts</Badge>
                </div>
              </CardContent>
            </Card>

            {/* Product Filter */}
            <Card className="border-0 shadow-lg shadow-slate-200/50">
              <CardHeader className="pb-3">
                <CardTitle className="text-sm font-semibold text-slate-600 flex items-center gap-2">
                  <Filter className="w-4 h-4" />
                  Filter by Product
                </CardTitle>
              </CardHeader>
              <CardContent className="space-y-2">
                {products.map(product => (
                  <label key={product.id} className="flex items-center gap-3 cursor-pointer">
                    <Checkbox defaultChecked />
                    <span className="text-sm text-slate-700">{product.shortName}</span>
                    <div className={`w-2 h-2 rounded-full bg-${product.color}-500 ml-auto`} />
                  </label>
                ))}
              </CardContent>
            </Card>
          </motion.div>

          {/* Week View */}
          <motion.div
            initial={{ opacity: 0, y: 20 }}
            animate={{ opacity: 1, y: 0 }}
            className="lg:col-span-3"
          >
            <Card className="border-0 shadow-lg shadow-slate-200/50">
              <CardHeader className="pb-4 border-b border-slate-100">
                <div className="flex items-center justify-between">
                  <CardTitle className="text-lg font-semibold">
                    {format(currentWeekStart, 'MMMM yyyy')}
                  </CardTitle>
                  <div className="flex items-center gap-2">
                    <Button 
                      variant="outline" 
                      size="icon"
                      onClick={() => navigateWeek('prev')}
                      className="h-8 w-8"
                    >
                      <ChevronLeft className="w-4 h-4" />
                    </Button>
                    <Button 
                      variant="outline" 
                      size="sm"
                      onClick={() => setCurrentWeekStart(startOfWeek(new Date(), { weekStartsOn: 1 }))}
                    >
                      Today
                    </Button>
                    <Button 
                      variant="outline" 
                      size="icon"
                      onClick={() => navigateWeek('next')}
                      className="h-8 w-8"
                    >
                      <ChevronRight className="w-4 h-4" />
                    </Button>
                  </div>
                </div>
              </CardHeader>
              <CardContent className="p-0">
                <div className="grid grid-cols-7 border-b border-slate-100">
                  {weekDays.map((day, index) => (
                    <div 
                      key={index}
                      className={`text-center py-4 border-r last:border-r-0 border-slate-100 ${
                        isToday(day) ? 'bg-blue-50' : ''
                      }`}
                    >
                      <p className="text-xs text-slate-500 uppercase">
                        {format(day, 'EEE')}
                      </p>
                      <p className={`text-lg font-semibold mt-1 ${
                        isToday(day) ? 'text-blue-600' : 'text-slate-900'
                      }`}>
                        {format(day, 'd')}
                      </p>
                    </div>
                  ))}
                </div>
                <div className="grid grid-cols-7 min-h-[400px]">
                  {weekDays.map((day, dayIndex) => {
                    const dayPosts = getPostsForDate(day);
                    return (
                      <div 
                        key={dayIndex}
                        className={`border-r last:border-r-0 border-slate-100 p-2 ${
                          isToday(day) ? 'bg-blue-50/30' : ''
                        }`}
                      >
                        <AnimatePresence>
                          {dayPosts.map((post, postIndex) => {
                            const PostIcon = getPostTypeIcon(post.type);
                            const color = getProductColor(post.product);
                            return (
                              <motion.div
                                key={post.id}
                                initial={{ opacity: 0, scale: 0.9 }}
                                animate={{ opacity: 1, scale: 1 }}
                                exit={{ opacity: 0, scale: 0.9 }}
                                transition={{ delay: postIndex * 0.05 }}
                              >
                                <Link to={createPageUrl('PostEditor') + `?id=${post.id}`}>
                                  <div className={`mb-2 p-2 rounded-lg bg-white border border-${color}-200 hover:border-${color}-300 shadow-sm hover:shadow-md transition-all cursor-pointer group`}>
                                    <div className="flex items-center gap-1.5 mb-1">
                                      <div className={`w-5 h-5 rounded flex items-center justify-center bg-${color}-100`}>
                                        <PostIcon className={`w-3 h-3 text-${color}-600`} />
                                      </div>
                                      <span className="text-[10px] text-slate-500">{post.time}</span>
                                    </div>
                                    <p className="text-xs font-medium text-slate-800 line-clamp-2 leading-tight">
                                      {post.title}
                                    </p>
                                    <div className="flex items-center justify-between mt-1.5">
                                      <Badge className={`text-[9px] px-1 py-0 bg-${color}-100 text-${color}-700 border-0`}>
                                        {products.find(p => p.id === post.product)?.shortName}
                                      </Badge>
                                      {post.status === 'draft' && (
                                        <span className="text-[9px] text-amber-600">Draft</span>
                                      )}
                                    </div>
                                  </div>
                                </Link>
                              </motion.div>
                            );
                          })}
                        </AnimatePresence>
                        <Button 
                          variant="ghost" 
                          size="sm" 
                          className="w-full h-7 text-xs text-slate-400 hover:text-slate-600 opacity-0 hover:opacity-100"
                        >
                          <Plus className="w-3 h-3 mr-1" />
                          Add
                        </Button>
                      </div>
                    );
                  })}
                </div>
              </CardContent>
            </Card>
          </motion.div>
        </div>
      </div>
    </div>
  );
}