1+ <?php 
2+ 
3+ namespace  Rappasoft \LaravelLivewireTables \Features \Sorting \Concerns ;
4+ 
5+ use  Illuminate \Database \Eloquent \Builder ;
6+ use  Livewire \Attributes \{Computed ,On };
7+ use  Rappasoft \LaravelLivewireTables \Features \Columns \Views \Column ;
8+ 
9+ trait  HandlesSortingPills
10+ {
11+     /** 
12+      * Undocumented function 
13+      * 
14+      * @return boolean 
15+      */ 
16+     public  function  getSortingPillsStatus (): bool 
17+     {
18+         return  $ this sortingConfig ['sortingPillsStatus ' ] ?? true ;
19+     }
20+ 
21+     /** 
22+      * Undocumented function 
23+      * 
24+      * @return string 
25+      */ 
26+     #[Computed]
27+     public  function  getDefaultSortingLabelAsc (): string 
28+     {
29+         return  $ this sortingConfig ['defaultSortingLabelAsc ' ] ?? 'A-Z ' ;
30+     }
31+ 
32+ 
33+     /** 
34+      * Undocumented function 
35+      * 
36+      * @return string 
37+      */ 
38+     #[Computed]
39+     public  function  getDefaultSortingLabelDesc (): string 
40+     {
41+         return  $ this sortingConfig ['defaultSortingLabelDesc ' ] ?? 'Z-A ' ;
42+     }
43+ 
44+ 
45+     /** 
46+      * Undocumented function 
47+      * 
48+      * @return array<mixed> 
49+      */ 
50+     public  function  getSortsForPills (): array 
51+     {
52+         $ sortedCols
53+         $ defaultSortingLabelAsc$ this getDefaultSortingLabelAsc ();
54+         $ defaultSortingLabelDesc$ this getDefaultSortingLabelDesc ();
55+         $ sortKeysarray_keys ($ this sorts );
56+         foreach ($ this getColumns ()
57+             ->visibleSortableColumns ()
58+             ->reject (fn  (Column $ columnin_array ($ columngetSlug (), $ sortKeysin_array ($ columngetTitle (), $ sortKeysas  $ sortedColumn
59+         {
60+             $ columnSelectName$ sortedColumngetSlug ();
61+             $ direction$ this sorts [$ columnSelectName
62+             $ sortingPillTitle$ sortedColumngetSortingPillTitle ();
63+             $ sortingPillDirectionLabel$ sortedColumngetSortingPillDirectionLabel ($ direction$ defaultSortingLabelAsc$ defaultSortingLabelDesc
64+ 
65+             $ sortedCols
66+                 'columnSelectName '  => $ columnSelectName
67+                 'direction '  => $ direction
68+                 'sortingPillTitle '  => $ sortingPillTitle
69+                 'sortingPillDirectionLabel '  => $ sortingPillDirectionLabel
70+             ];
71+         } 
72+         return  $ sortedCols
73+     }
74+ 
75+ 
76+     /** 
77+      * Undocumented function 
78+      * 
79+      * @return boolean 
80+      */ 
81+     public  function  sortingPillsAreEnabled (): bool 
82+     {
83+         return  $ this getSortingPillsStatus () === true ;
84+     }
85+ 
86+     /** 
87+      * Undocumented function 
88+      * 
89+      * @return boolean 
90+      */ 
91+     public  function  sortingPillsAreDisabled (): bool 
92+     {
93+         return  $ this getSortingPillsStatus () === false ;
94+     }
95+ 
96+     /** 
97+      * Undocumented function 
98+      * 
99+      * @return boolean 
100+      */ 
101+     #[Computed]
102+     public  function  showSortPillsSection (): bool 
103+     {
104+         return  $ this sortingIsEnabled () && $ this sortingPillsAreEnabled () && $ this hasSorts ();
105+     }
106+     
107+     /** 
108+      * Undocumented function 
109+      * 
110+      * @param boolean $status 
111+      * @return self 
112+      */ 
113+     public  function  setSortingPillsStatus (bool  $ statusself 
114+     {
115+         $ this sortingConfig ['sortingPillsStatus ' ] = $ status
116+ 
117+         return  $ this 
118+     }
119+ 
120+     /** 
121+      * Undocumented function 
122+      * 
123+      * @return self 
124+      */ 
125+     public  function  setSortingPillsEnabled (): self 
126+     {
127+         return  $ this setSortingPillsStatus (true );
128+     }
129+ 
130+     /** 
131+      * Undocumented function 
132+      * 
133+      * @return self 
134+      */ 
135+     public  function  setSortingPillsDisabled (): self 
136+     {
137+         return  $ this setSortingPillsStatus (false );
138+     }
139+ 
140+     /** 
141+      * Undocumented function 
142+      * 
143+      * @param string $asc 
144+      * @param string $desc 
145+      * @return self 
146+      */ 
147+     public  function  setDefaultSortingLabels (string  $ ascstring  $ descself 
148+     {
149+         $ this sortingConfig ['defaultSortingLabelAsc ' ] = $ asc
150+         $ this sortingConfig ['defaultSortingLabelDesc ' ] = $ desc
151+ 
152+         return  $ this 
153+     }
154+ 
155+ }
0 commit comments